[英]Overlapping titles with R plot command?
目前,我在尝试绘制图形时无法使用R studio。 我只想让Y轴说:迭代的E(sigma)和X轴只说:列表大小。 不幸的是,它是重叠的,无法阅读。 有没有办法解决这个问题。 我为自己的无知表示歉意,但为了避免使用Excel,我自学了R,所以我确实是个新手。 感谢您的所有帮助。 这是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))
根据您的评论,我做到了:
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)
现在y值被重叠了。 我很抱歉第一次没有清楚地说明自己。 谢谢您的帮助。
这不是RStudio
问题。 默认情况下, plot
功能根据绘图中x和y变量的名称将x和y轴标题添加到绘图中。 您可以通过将它们更改为空字符串来消除它们,然后在完成后添加它们。 或者,您可以直接在plot命令中添加它们。 根据我猜测您要执行的操作,我对您的代码进行了一些更改。 如果我猜错了,请告诉我:
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))
下面的代码直接在plot命令中添加主轴和x轴和y轴标题。 然后,您运行与上面相同的代码,但是跳过对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)
这是结果图:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.