【问题标题】:wrong linking point with lines in ggplotggplot中与线的错误链接点
【发布时间】:2014-02-11 11:31:16
【问题描述】:

我不知道我错过了什么,但我无法弄清楚一个非常简单的任务。这是我数据框的一小部分:

dput(df)
structure(list(ID = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L), .Label = "SOU55", class = "factor"), Depth = c(2L, 4L, 
6L, 8L, 10L, 12L, 14L, 16L, 18L, 20L), Value = c(211.8329815, 
278.9603866, 255.6111086, 212.6163368, 193.7281895, 200.9584658, 
160.9289157, 192.0664419, 174.5951019, 7.162682425)), .Names = c("ID", 
"Depth", "Value"), class = "data.frame", row.names = c(NA, -10L
))

我想要做的只是用 ggplot 绘制深度与值,这是简单的代码:

ggplot(df, aes(Value, Depth))+
  geom_point()+
  geom_line()

结果如下:

但这与我真正想要的完全不同。这是使用 Libreoffice 制作的情节:

似乎 ggplot 没有正确链接这些值。我做错了什么?

谢谢大家!

【问题讨论】:

  • 错误geom。只需改用geom_path()

标签: r ggplot2


【解决方案1】:

您需要geom_path() 以原始顺序连接观察结果。 geom_line()在绘图前根据x-aesthetic对数据进行排序:

ggplot(df, aes(Value, Depth))+ geom_point()+ geom_path()

【讨论】:

  • ahrrrrrrrr.. 就是这样!谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-23
  • 2011-07-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多