为什么这段代码没有在y的相同值的数据之间划线?
main <- data_frame(x=rep(c(-1, 1), each=2), y = c(c(1, 1), c(2, 2)), z = c(1, 2, 3, 4))
qplot(data = main, x = x, y = z, geom="line", group=factor(y))
这是我得到的:
但我只希望连接y级别的点。
答案 0 :(得分:4)
The issue is with how you defined your y
variable. Change it to y = c(c(1,2), c(1,2))
and things should work.
Also, if you're going to use data_frame
be sure to add the calls to library
to make your code reproducible (i.e., library(dplyr)
and library(ggplot2)
).