R 如何在geom_功能区上生成具有geom_点范围的单个绘图?(基本上显示数据点及其标准偏差)
我这里有两个图PlotA和PlotB,但是我想要一个组合图,其中geom_pointranges显示点,geom_line显示线,geom_ribbon显示标准偏差R 如何在geom_功能区上生成具有geom_点范围的单个绘图?(基本上显示数据点及其标准偏差),r,ggplot2,R,Ggplot2,我这里有两个图PlotA和PlotB,但是我想要一个组合图,其中geom_pointranges显示点,geom_line显示线,geom_ribbon显示标准偏差 water <- c(35,40,42,46,48,50) depth <- c(1,2,3,4,5,6) sd <- c(10,10,10,10,10,10) dataA <- data.frame(depth, water, sd) from <- c(0.5, 1.5, 2.5, 3.5, 4.
water <- c(35,40,42,46,48,50)
depth <- c(1,2,3,4,5,6)
sd <- c(10,10,10,10,10,10)
dataA <- data.frame(depth, water, sd)
from <- c(0.5, 1.5, 2.5, 3.5, 4.5, 5.5)
to <- c(1.5, 2.5, 3.5, 4.5, 5.5, 6.5)
depth1 <- c(1,2,3,4,5,6)
water1 <- c(40,32,50,55,62,30)
dataB <- data.frame(from,to,depth1, water1)
# Load necessary packages
require(ggplot2)
# Plotting Started
#PlotA
ggplot(data=dataA, aes(x = water, y = depth), na.rm=T) +
geom_path(size=0.4, color="black")+
geom_pointrange(data=dataB, aes(water1, depth1, ymin=from, ymax=to), size=0.1, color='black') +
scale_y_reverse(lim = c(10,0), breaks = seq(0,10,1)) +
theme_bw(12) +
scale_x_continuous(lim =c(0,100), breaks = seq(0,100,20))
#PlotB
ggplot() + geom_ribbon(data=dataA, aes(x=depth, y=water, ymin = water - sd, ymax = water + sd), alpha=0.3, fill='grey12') + coord_flip() +
scale_x_reverse(lim = c(10,0), breaks = seq(0,10,1)) + theme_bw(12) +
scale_y_continuous(lim =c(0,100), breaks = seq(0,100,20))
CODRY翻转是很难在情节中间使用的。我强烈建议调试没有它的绘图,然后添加它作为最后一步
我想这就是你要找的。如果没有,请更详细地描述您想要的结果ggplot(data = dataA, aes(x = depth, y = water)) +
geom_ribbon(
data = dataA,
aes(
x = depth,
ymin = water - sd,
ymax = water + sd
),
alpha = 0.3,
fill = 'grey12'
) +
geom_path(size = 0.4, color = "black") +
geom_point(
data = dataB,
aes(x = depth1, y = water1),
size = 0.1,
color = 'black'
) +
geom_errorbarh(
data = dataB,
aes(
x = depth1,
xmin = from,
xmax = to,
y = water1
),
size = 0.1,
height = 0
) +
theme_bw(12) +
scale_x_reverse(lim = c(10, 0), breaks = seq(0, 10, 1)) +
scale_y_continuous(lim = c(0, 100), breaks = seq(0, 100, 20)) +
coord_flip()
请更新您的问题,因为不清楚您期望的最终结果是什么。我只想要一个单独的图形,其中绘图a和绘图B相互结合。标题已更新。我希望现在有点清楚了。谢谢,这没用,我的答案在色带上有点…看起来你的问题中没有使用zoo、ggvis、gridExtra、dplyr和cowplot-我建议删除它们。这真是一个神奇的方法。工作100%良好。正是我想要的。非常感谢你,格雷戈。那真是太棒了。