我计划在同一张图中绘制x轴上多个参数的垂直剖面,例如盐度,温度,密度,与y轴对应的压力。这是我希望得到的那种情节:

以下是我的数据中的一个示例:
ï..IntD.Date. IntT.Time. Salinity..psu. SIGMA.Kg.m3. Pressure.dbar.
1 21-April-2019 5:31:55 PM 30.2502 20.2241 0.7160
2 21-April-2019 5:32:00 PM 31.0254 20.8081 0.8409
3 21-April-2019 5:32:05 PM 31.2654 20.9930 1.0551
4 21-April-2019 5:32:10 PM 31.2953 21.0176 1.2694
Temp..0C. Vbatt.volt.
1 23.4054 12.29
2 23.4148 12.30
3 23.4060 12.29
4 23.4024 12.33 我已经使用了这些代码:
data <- read.csv('file location')
vert_plot <- ggplot(data, aes(x = Pressure.dbar., y = Temp..0C.)) + geom_line(color = '#088DA5', size = 0.75) + labs(size = 18) + ggtitle("temp vs pressure") + theme_grey() + coord_flip() + scale_y_reverse()它生成了这个图:

正如你所看到的,我能够带来一个单一的轮廓,其中y轴的比例不是逆序的,而我更喜欢压力值(0,5,10....)。从左上角开始。与我绘制的压力值从左下角开始绘制的图不同。
如果有人能帮我计算一下,我可以在同一张图中绘制多个垂直剖面,其中y轴是压力,并且是相反的顺序,如势垒层厚度图所示,我将非常感激。
发布于 2020-05-21 21:02:29
根据需要添加任意数量的geom_line(),并在每个geom_line()中调用aes。对于5个断点,添加scale_x_continuous并调用其中的断点序列。
vert_plot <- ggplot(df) +
geom_line(aes(x = Pressure.dbar., y = Temp..0C.), color = 'blue', size = 0.75) +
geom_line(aes(x = Pressure.dbar., y = Salinity..psu.), color = 'red', size = 0.75) +
geom_line(aes(x = Pressure.dbar., y = SIGMA.Kg.m3.), color = 'green', size = 0.75) +
labs(size = 18) + ggtitle("Dummy Title") + xlab("Pressure") + ylab("Dummy Label") +
scale_x_reverse(limits = c(40, 0), breaks = seq(40, 0, -5)) +
theme_grey() + coord_flip() + scale_y_reverse()

替代方法:
而不是经历所有这些,您可以融化数据框,保持变量名称为组。
library(reshape2)
newdf <- melt(df, id.vars = c("IntD.Date.", "IntT.Time.", "Pressure.dbar."),
variable.name = "group")
vert_plot <- ggplot(newdf, aes(x = Pressure.dbar., y = value, color = group)) +
geom_line(size = 0.75) +
labs(size = 18) + ggtitle("Dummy Title") +
xlab("Pressure") + ylab("Dummy Label") +
scale_x_reverse(limits = c(40, 0), breaks = seq(40, 0, -5)) +
theme_grey() + coord_flip() + scale_y_reverse()

https://stackoverflow.com/questions/61933906
复制相似问题