You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在R中用patchwork实现环形箱线图的叠加显示?

实现环形箱线图叠加的两种方法

patchwork可以实现这个需求,不过因为CircularBoxplot属于R基础绘图系统(非ggplot2对象),有两种更直接的方案:

方法一:直接用基础绘图的叠加参数

CircularBoxplot函数自带add=TRUE参数,支持在已有绘图的基础上叠加新图形,无需依赖patchwork:

library(circular)
data(fisherB12c)
library(bpDir)

# 绘制第一个环形箱线图
CircularBoxplot(fisherB12c, template="geographics")
# 叠加缩小版的第二个图,add=TRUE表示不新建画布
CircularBoxplot(fisherB12c, template="geographics", shrink = 2, add = TRUE)

方法二:用patchwork的嵌入功能

如果需要整合到patchwork的绘图流程中,可以通过inset_element将第二个图嵌入到第一个图的整个画布区域,实现叠加:

library(circular)
data(fisherB12c)
library(bpDir)
library(patchwork)

p <- wrap_elements(full = ~CircularBoxplot(fisherB12c, template="geographics")) 
p2 <- wrap_elements(full = ~CircularBoxplot(fisherB12c, template="geographics", shrink = 2)) 

# 将p2完全覆盖在p上方
p + inset_element(p2, left = 0, bottom = 0, right = 1, top = 1)

两种方法都能生成同一画布上不同半径的环形箱线图,第一种更高效,第二种适合已有patchwork绘图体系的场景。

内容的提问来源于stack exchange,提问作者user3236841

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 07:40:06