这是一个简单的任务,但由于某种原因它没有给我想要的输出。
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")
我想绘制 x1,y1 并用线连接这些点,但线不是 显示。 我使用轴是因为我希望显示这些特定标签。
有什么建议吗?
最佳答案
您还必须给出要绘制的 x 坐标。
此外,您还必须修改轴函数中的 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(x1, y1, col = "gray")
请注意,您可以指定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")
一次获取线和点。
关于r - R中绘图中的连接点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51742472/