我正在尝试制作一个简单的线条图,但我收到以下错误:
geom_path:每组只包含一个观察。你需要吗? 调整群体审美?
我想在y轴上运行status.std,在x轴上运行,使用status_measure来区分两条单独的线。
以下是我的数据和我正在执行的代码:
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()
非常感谢您的帮助。我很遗憾这个问题似乎不太可能对其他人有所帮助。如果有一个标题编辑或某些东西会使它更加通用,那就太棒了。
答案 0 :(得分:2)
语法错误。需要移动paren以便aes(...)同时获取x和y参数(但不是颜色参数,因为只需移动到最后就会生成您发布的错误。)
ggplot(data=df.effort,
aes(x=effort, y=status.std), colour=status_measure) + geom_line()
哪个成功但没有给任何颜色着色。无论如何,如何为线条挑选颜色?我认为颜色会粘在点上,所以试试这个:
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))
或许你确实想要joran发布的内容:
ggplot(data=df.effort,
aes(x=effort, y=status.std, colour=status_measure, group=status_measure)) +
geom_line()
(我以为你试图使用geom_line将努力类别中的测量值与区分状态测量值的颜色联系起来。)