有没有办法将geom_ribbon()添加到基于融合数据帧的ggplot()?
例如,下面的简单示例应绘制两行。我想添加一个geom_ribbon()并使用line2作为min和line1作为max(基本上填充b / w行的区域)。一个更复杂的例子最终将在数据框中有几条非线性线,我想创建一个使用特定线数据作为下限和上限的功能区。
library(ggplot2)
library(gtable)
library(reshape2)
library(grid)
library(scales)
df.test <-
data.frame(
x_cat = factor(c(1, 2, 3, 4)),
count = seq(1:4),
line1 = seq(from = 1, to = 4, length.out = 4),
line2 = seq(from = 0, to = 3, length.out = 4)
)
df.melted <- melt( df.test[-2] )
p1 <- ggplot( data = df.melted , aes(x=x_cat, y=value, colour=variable ) ) +
geom_line( aes(group=variable) ) +
ylab( "Y Label 2" ) +
theme(panel.background = element_rect(fill = NA, colour = "white"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "bottom")
g<- ggplotGrob(p1)
grid.draw(g)