如何让ggplot2中QQ图的数据点置于strip下方?
QQ图数据点显示在Strip上方的解决方法
问题描述
想要制作目标样式的QQ图,但目前QQ图的数据点显示在分标题栏(strip)上方,遮挡了strip区域:
- 期望效果:数据点完整显示在每个分面的面板内,strip清晰显示在面板上方,无遮挡
- 当前效果:数据点超出面板范围,覆盖在strip区域上
问题原因
你的主题设置中使用了strip.clip="off",这个参数会关闭strip区域的裁剪限制,允许面板内的元素(比如QQ图的点)延伸到strip区域上方。
解决方法
移除strip.clip="off",或者将其设置为默认值strip.clip="on",即可限制数据点只在面板范围内显示,不会跑到strip上方。
修正后的代码
my_theme <- theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), plot.title = element_text(size = 10), panel.background = element_rect(fill = "white", color = "gray50", size=3.5), # 移除strip.clip="off",或改为strip.clip="on" strip.background = element_rect(color = "gray50",fill = "lightgray", size = 1.5), legend.background=element_rect(fill = "lightgray", color="gray50", size=1.5), legend.key = element_rect(fill = "lightgray", size=4), axis.ticks.x = element_blank(), axis.ticks.y = element_blank(), legend.key.height = unit(1, "cm"), legend.key.width = unit(1, "cm")) ggplot(data = melted_df, aes(sample = value, color = Distribution)) + stat_qq(position = "identity") + geom_qq_line() + facet_wrap(~Distribution, scales = "free") + xlab('理论分位数') + ylab('样本分位数') + ggtitle('不同分布与正态分布的QQ图对比') + my_theme
内容的提问来源于stack exchange,提问作者qqplotter
相关产品推荐
相关产品推荐

