简体   繁体   English

用R plot命令重叠标题?

[英]Overlapping titles with R plot command?

Currently, I am having trouble using R studio when I try to graph things. 目前,我在尝试绘制图形时无法使用R studio。 I want to have the Y axis only say: E(sigma) of iteration and the X axis to only say: List size. 我只想让Y轴说:迭代的E(sigma)和X轴只说:列表大小。 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. 我为自己的无知表示歉意,但为了避免使用Excel,我自学了R,所以我确实是个新手。 Thanks for all the help. 感谢您的所有帮助。 Here is the R code: 这是R代码:

  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. 现在y值被重叠了。 i apologize for not explaining myself clearly the first time. 我很抱歉第一次没有清楚地说明自己。 thanks for the help. 谢谢您的帮助。

Here is the picture 这是图片 图形

This isn't an RStudio issue. 这不是RStudio问题。 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. 默认情况下, plot功能根据绘图中x和y变量的名称将x和y轴标题添加到绘图中。 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. 或者,您可以直接在plot命令中添加它们。 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. 下面的代码直接在plot命令中添加主轴和x轴和y轴标题。 Then you run the same code as above, but skip the three calls to title . 然后,您运行与上面相同的代码,但是跳过对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: 这是结果图:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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