R ggplot中的线连接点错误

R ggplot中的线连接点错误,r,ggplot2,R,Ggplot2,我不知道我遗漏了什么,但我无法找出一个非常简单的任务。这是我的数据帧的一小部分: 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.960

我不知道我遗漏了什么,但我无法找出一个非常简单的任务。这是我的数据帧的一小部分:

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_path()
以原始顺序连接观测值
geom_line()
在打印前根据
x
-美学对数据进行排序:


ggplot(df、aes(值、深度))+
几何点()+
几何路径()

错误
geom
。只需使用
geom_path()
即可。。就这样!谢谢