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. I am using axes because I want these specific labels to show.
我想绘制x1,y1并用一条线连接点,但该线未显示。我正在使用轴,因为我想要显示这些特定的标签。
Any recommendations?
有什么建议?
2 个解决方案
#1
1
You have to give the x-coordinates to plot as well. Also you have to modify the at
argument in your axis function.
您还必须给出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(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.
一次获得线条和点数。
#2
0
As hint, you can also think to use ggplot to create a fancy plot:
作为提示,您还可以考虑使用ggplot创建一个奇特的情节:
# your data as data.frame
data <- data.frame (
x1 = c(100000,250000,500000,750000,1000000),
y1 = c(1.076904,3.917412,12.365130,23.084268,37.234246))
# the plot
ggplot(aes(x1, y1), data = data) +
geom_point( size = 5) +
geom_path (linetype=1, size=0.5, arrow = arrow(angle=15, type="closed"))+ # remove the arrow() to not have the arrow
geom_point(aes(x1, y1), data = data, size = 5) +
labs(x = "x", y = "y", color = "method")
#1
1
You have to give the x-coordinates to plot as well. Also you have to modify the at
argument in your axis function.
您还必须给出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(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.
一次获得线条和点数。
#2
0
As hint, you can also think to use ggplot to create a fancy plot:
作为提示,您还可以考虑使用ggplot创建一个奇特的情节:
# your data as data.frame
data <- data.frame (
x1 = c(100000,250000,500000,750000,1000000),
y1 = c(1.076904,3.917412,12.365130,23.084268,37.234246))
# the plot
ggplot(aes(x1, y1), data = data) +
geom_point( size = 5) +
geom_path (linetype=1, size=0.5, arrow = arrow(angle=15, type="closed"))+ # remove the arrow() to not have the arrow
geom_point(aes(x1, y1), data = data, size = 5) +
labs(x = "x", y = "y", color = "method")