【发布时间】:2020-03-19 19:11:45
【问题描述】:
我知道在两条具有相同x值的y曲线之间制作阴影区域如下:
geom_ribbon(data=dataframe,aes(ymin = y_lwr, ymax = y_upr), fill = "grey")
但是,有谁知道我们如何绘制具有不同 x 值的两条曲线之间的阴影区域?
当下方曲线由(x_lwr, y_lwr) 定义且上方曲线由(x_upr, y_upr) 定义时
完整的数据集应该生成如下图:
我的示例数据和代码如下:
> head(df)
y1 x1 y_lwr x_lwr y_upr x_upr
#> 1 11.60 67.01 4.97 86.28 14.54 58.17
#> 2 11.32 68.57 4.51 88.99 13.74 61.67
#> 3 10.76 71.63 4.15 91.29 13.00 64.74
#> 4 10.19 75.52 3.82 92.69 12.35 67.83
#> 5 9.91 77.33 3.60 94.19 11.71 70.84
#> 6 9.62 79.14 3.46 94.90 11.21 73.33
pltS <- ggplot(data=df, aes(x=df[,2], y=df[,1]))+
ylab("log(y)")+ xlab("x")
pltS <- pltS + geom_point(pch = 16, col="black", size=1)
# upper and lower bands
plt <- plt + geom_line(aes(x=df[,4], y=df[,3]), col="grey", size=1)
plt <- plt + geom_line(aes(x=df[,6], y=df[,5]), col="grey", size=1)
# x-axis & y-axis specifications
plt <- plt + theme(aspect.ratio=1)+
scale_y_continuous(trans = 'log10')+
annotation_logticks(sides="l")+
scale_x_continuous(labels = function(x) paste0(x, "%"))
plt
【问题讨论】:
-
请查看How to make a great R reproducible example,以修改您的问题,并从您的数据中提取较小的样本(查看
?dput())。发布您的数据或没有数据的图像会使我们难以为您提供帮助! -
查看
geom_polygon -
geom_polygon 没有给出我想要的图形!
标签: r ggplot2 data-visualization ribbon