【发布时间】:2019-03-30 10:59:02
【问题描述】:
我想制作 3 个堆叠线图,L、F 和 P,它们都具有共同的 x 轴深度,并且点由 Depo 着色。我找到了多种堆叠图表的方法,但我正在努力整合我想要的点颜色编码。
这是一些示例数据 - 抱歉,由于某种原因,它不会保留为表格格式
depth L F P Depo
67.48 1.003 1.063 1.066 Turb
67.63 1.004 1.020 1.024 Dri
67.73 1.011 1.017 1.028 Dri
67.83 1.006 1.007 1.014 Turb
67.92 1.003 1.029 1.032 Pro
68.06 1.004 1.007 1.011 Pro
我可以通过制作图表然后使用 grid.draw 堆叠它们来获得我想要的东西。但这会重复每个图形的 x 轴值。
Lin <- ggplot(MyData, aes(x=depth, y=L)) + geom_line() + geom_point(data = MyData, aes(x=depth, y=L, color = Depo))
Fab <- ggplot(MyData, aes(x=depth, y=P)) + geom_path() + geom_point(data = MyData, aes(x=depth, y=P, color = Depo))
Fol <- ggplot(MyData, aes(x=depth, y=F)) + geom_path() + geom_point(data = MyData, aes(x=depth, y=F, color = Depo))
grid.draw(rbind(ggplotGrob(Fol), ggplotGrob(Lin), ggplotGrob(Fab), size = "last"))
以下作品可以在不重复 x 轴的情况下绘制图表,但我不知道如何通过 Depo 更改点。
mm <- melt(subset(MyData, select=c(depth, L, F,P)), id.var="depth")
ggplot(mm, aes(x = depth, y = value)) + geom_line(aes(color = variable)) +
facet_grid(variable ~ ., scales = "free_y") + theme(legend.position = "none")
【问题讨论】: