简体   繁体   English

R中绘图中的连接点

[英]connecting points in plot in R

this is a simple task but for some reason it is not giving me the desired output.这是一项简单的任务,但由于某种原因,它没有给我所需的输出。

x1 = c(100000,250000,500000,750000,1000000)
y1 = c(1.076904,3.917412,12.365130,23.084268,37.234246)
plot(y1, pch=5, ylim=c(1,50),xlab="Sample Size", ylab="Time(s)" , main = "Time relative to Sample Size-NonGreedy", xaxt = "n")
axis(1, at=1:5, labels = x1)
lines(x1,y1, col = "gray")

I want to plot x1,y1 and connect the points with a line, but the line is not showing.我想绘制 x1,y1 并用一条线连接这些点,但这条线没有显示。 I am using axes because I want these specific labels to show.我使用轴是因为我希望显示这些特定标签。

Any recommendations?有什么建议吗?

You have to give the x-coordinates to plot as well.您还必须给出要绘制的 x 坐标。 Also you have to modify the at argument in your axis function.您还必须修改轴函数中的at参数。

   x1 = c(100000,250000,500000,750000,1000000)
    y1 = c(1.076904,3.917412,12.365130,23.084268,37.234246)
    plot(x1, y1, pch=5, ylim=c(1,50),xlab="Sample Size", ylab="Time(s)" , main = "Time relative to Sample Size-NonGreedy", xaxt = "n")
    axis(1, at=x1, labels = x1)
    lines(xx1,y1, col = "gray")

Note that you can specify type = "b"请注意,您可以指定type = "b"

plot(x1, y1, pch=5, ylim=c(1,50),xlab="Sample Size", ylab="Time(s)" , 
     main = "Time relative to Sample Size-NonGreedy", xaxt = "n", type = "b")

to get lines and points at once.一次获得线和点。

只需在绘图函数参数中添加“type = l”(l 代表线)

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

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