简体   繁体   中英

Overlapping titles with R plot command?

Currently, I am having trouble using R studio when I try to graph things. I want to have the Y axis only say: E(sigma) of iteration and the X axis to only say: List size. Unfortunately it is overlapping and one cannot read it. Is there a way to fix this. I apologize for my ignorance, but I am self-teaching myself R in order to avoid using Excel, so I really am a novice. Thanks for all the help. Here is the R code:

  N = c(100, 200, 300, 400, 500, 600, 700, 800, 900, 1000)
  Shell Sort = c(100, 200, 300, 400, 500, 600, 700, 800, 900, 1000 )
  M = c(100, 200, 300, 400, 500, 600, 700, 800, 900, 1000 )
  plot(N, M, type = "o", col = "green");par(new=TRUE)
  plot(N, Shell Sort, type = "o", col = "blue")
  legend('topleft', col = c("black", "red"), lty = 1, 
         legend = c("N", "Shell Sort"), bty='n', cex=.59)
  title(main="Comparisons - Speed", col.main="black", font.main=4)
  title(xlab="List size", col.lab=rgb(0,0.5,0))
  title(ylab="∑ of iterations", col.lab=rgb(0,0.5,0))

From what I read from your comment I did this:

        N = c(100, 200, 300, 400, 500, 600, 700, 800, 900, 1000)
        InsertionSort = c(33, 80, 127, 177, 245, 318, 420, 532, 654, 815 )
        ShellSort = c(18, 48, 111, 156, 213, 283, 360, 451, 566, 684 )
        plot(N, InsertionSort, type = "o", col = "green", 
             xlab="List size", ylab="∑ of iterations", col.lab=rgb(0,0.5,0),
             main="Comparisons - Speed", col.main="black", font.main=4)
        par(new=TRUE)
        plot(N, ShellSort, type = "o", col = "blue", 
             xlab="", ylab="")

        legend('topleft', col = c("black", "red"), lty = 1, 
               legend = c("N", "Shell Sort"), bty='n', cex=.9)

and now the y values are being overlapped. i apologize for not explaining myself clearly the first time. thanks for the help.

Here is the picture 图形

This isn't an RStudio issue. The plot function by default adds x and y axis titles to your plot based on the names of the x and y variables in the plot. You can get rid of those by changing them to the empty string and then add them later as you've done. Or, you can just add them directly in the plot command. I've made a few changes to your code, based on what I'm guessing you're trying to do. Let me know if I've guessed wrong:

N = seq(100,1000,100)
ShellSort = seq(100,1000,100)
M = seq(50,950,100)

plot(N, M, type = "o", col = "green", xlab="", ylab="")
#par(new=TRUE)
lines(N, ShellSort, type = "o", col = "blue")

legend('topleft', col = c("black", "red"), lty = 1, 
       legend = c("N", "Shell Sort"), bty='n', cex=.59)

title(main="Comparisons - Speed", col.main="black", font.main=4)
title(xlab="List size", col.lab=rgb(0,0.5,0))
title(ylab="∑ of iterations", col.lab=rgb(0,0.5,0))

The code below adds the main and x- and y-axis titles directly in the plot command. Then you run the same code as above, but skip the three calls to title .

plot(N, M, type = "o", col = "green", 
     xlab="List size", ylab="∑ of iterations", col.lab=rgb(0,0.5,0),
     main="Comparisons - Speed", col.main="black", font.main=4)

And here's the resulting plot:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM