我沿着垂直剖面绘制了环境测量图,例如沿着沉积岩心,或者作为海洋深度的函数.按照惯例,这些图是垂直呈现的,沿y轴具有独立变量(深度).因此,线应该连接相邻y值的点.
ggplot2中的"line"geom似乎只是连接相邻x值的点.有没有解决的办法?
此示例创建一些逼真的数据并说明问题:
#generate fake data
sites<-factor(c(rep("site A", 10), rep("site B", 10)))
depths<-rep(1:10, 2)
values<-c(runif(10), runif(10)+2)
#make a visually pleasing scatter plot
qplot(values, depths, geom="point", col=sites)
Run Code Online (Sandbox Code Playgroud)
您可以从该图中看到我们正在查看与深度相关的测量值.但:
#make a visually meaningless scatter plot
qplot(values, depths, geom="line", col=sites)
Run Code Online (Sandbox Code Playgroud)
以毫无意义的方式连接点.有没有办法垂直连接点?
qplot(depths, values, geom="line", group=sites) + coord_flip()
Run Code Online (Sandbox Code Playgroud)
