Legend Horizontal Graph Spacing in R -
ok asked before, although have made more progress now, wasn't sure how add code comment of old post. anyways here new problem. using legend command creat horizontal leged , hoping there way reduce space between legend item list
# initial variables, fine t = 0:50 int_seq = seq(0,0.1,by=0.025) int_seq100 = 100 * int_seq colors = c("black","red","blue","green","orange") index = 1:length(int_seq) #av simple interest, fine avsimple = function(i,t){ av = (1 + (i * t)) return(av)} # plot range y-axis, fine yrange = c(avsimple(min(int_seq),min(t)) * 0.95, avsimple(max(int_seq),max(t)) * 1.15) # plots simple interest different interest rates, fine plot(t,avsimple(int_seq[1],t), type="l", main = "av simple interest", xlab = "time", ylab = "av", ylim = yrange) (i in index) lines(t,avsimple(int_seq[i],t), col = colors[i]) # adds legend plot different interest rates # trouble # ? , how can reduce distance between each index in labs string # space or 2 apart each other labs = c("i =:",sprintf('%s%%', c(int_seq100))) legend('topleft', legend = labs, text.col = c("black",colors), horiz = true, bty = "n")
the text.width comment can that. need play around numbers. changed smaller font size (cex) , set numbers 2 decimals (sprintf). last lines in script should changed following:
labs = c("i =:",sprintf('%.2f', c(int_seq100))) legend('topleft', text.width=c(0.3, 0.3, 0.3, 0.3, 0.3), cex = 0.75, legend = labs, text.col = c("black",colors), horiz = true, bty = "n")
Comments
Post a Comment