[英]error with simple ggplot2 line plot
I'm trying to make a simple line plot but I get the following error: 我正在尝试制作一个简单的线条图,但我收到以下错误:
geom_path: Each group consist of only one observation.
geom_path:每组只包含一个观察。 Do you need to adjust the group aesthetic?
你需要调整群体美感吗?
I want status.std on the y-axis, effort on the x-axis, with status_measure distinguishing the two separate lines. 我希望在y轴上的status.std,在x轴上的努力,status_measure区分两条单独的线。
Below is my data and the code I'm executing: 下面是我的数据和我正在执行的代码:
df.effort <- structure(list(effort = structure(c(1L, 2L, 3L, 4L, 1L, 2L, 3L,
4L), .Label = c("never", "not very hard", "hard enough", "very hard"
), class = "factor"), status.std = structure(c(-0.0234448237301297,
0.0568346993679614, 0.0780165665285588, -0.0380394621882508,
-0.135535917573711, 0.0128879641418037, 0.0806307867881565, -0.0104818763687783
), .Names = c("never", "not very hard", "hard enough", "very hard",
"never", "not very hard", "hard enough", "very hard")), status_measure = structure(c(1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c("avrank.zmgs", "acent09l.zmgs"
), class = "factor")), .Names = c("effort", "status.std", "status_measure"
), row.names = c(NA, 8L), class = "data.frame")
ggplot(data=df.effort,
aes(x=effort), y=status.std, colour=status_measure)) + geom_line()
Many thanks for any help. 非常感谢任何帮助。 I regret that this question seems unlikely to be instructive to others.
我很遗憾这个问题似乎不太可能对其他人有所帮助。 If there is a title edit or something that would make it more general that would be fantastic.
如果有一个标题编辑或某些东西会使它更通用,那将是太棒了。
Syntax error. 语法错误。 Need to move the paren so that aes(...) gets both the x and y arguments (but not the colour argument, because simply moving to the end generates the error you posted.)
需要移动paren以便aes(...)同时获取x和y参数(但不是颜色参数,因为只需移动到末尾就会生成您发布的错误。)
ggplot(data=df.effort,
aes(x=effort, y=status.std), colour=status_measure) + geom_line()
Which succeeds but fails to color anything. 哪个成功但没有给任何颜色着色。 And how could a color be picked for the lines anyway?
无论如何,如何为线条挑选颜色? I think the colors would adhere to the points, so try this:
我认为颜色会粘在点上,所以试试这个:
ggplot(data=df.effort, aes(x=effort, y=status.std))+
geom_line()+
geom_point(data=df.effort,
aes(x=effort, y=status.std, colour=status_measure))
Or maybe you do want what joran posted: 或许你确实想要joran发布的内容:
ggplot(data=df.effort,
aes(x=effort, y=status.std, colour=status_measure, group=status_measure)) +
geom_line()
(I thought you were trying to use geom_line to link measurements within category of effort with color distinguishing between status measures.) (我以为你试图使用geom_line将努力类别中的测量值与状态测量值之间的颜色区分开来。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.