R ggplot2面板层中的多个圆角矩形

R ggplot2面板层中的多个圆角矩形,r,ggplot2,treemap,rounded-corners,grob,R,Ggplot2,Treemap,Rounded Corners,Grob,我正在尝试创建带有圆角的树形图,就像这个 我用的是treemapify软件包 我曾尝试使用Claus-Wilke解决方案,将背景矩形更改为圆形矩形,如下所示: 我认为问题在于roundrectGrob()函数“绘制一个圆角矩形”,而这里我们有一个矩形列表 如何将单个rectGrob与roundrectGrob列表交换 事实上,如果我只选择一个元素,它可以正常工作(),但当然只打印第一个矩形: rounded_rects <- roundrectGrob(x=rects$x[[1]], y=

我正在尝试创建带有圆角的树形图,就像这个

我用的是treemapify软件包

我曾尝试使用Claus-Wilke解决方案,将背景矩形更改为圆形矩形,如下所示:

我认为问题在于roundrectGrob()函数“绘制一个圆角矩形”,而这里我们有一个矩形列表

如何将单个rectGrob与roundrectGrob列表交换

事实上,如果我只选择一个元素,它可以正常工作(),但当然只打印第一个矩形:

rounded_rects <- roundrectGrob(x=rects$x[[1]], y=rects$y[[1]], width=rects$width[[1]], height=rects$height[[1]],
                r=unit(0.1, "snpc"),
                just=rects$just, name=rects$name, gp=rects$gp, vp=rects$vp)
gg$grobs[[6]]$children[[3]] <- rounded_rects
cowplot::plot_grid(gg)
四舍五入
rounded_rects <- roundrectGrob(x=rects$x, y=rects$y, width=rects$width, height=rects$height,
                r=unit(0.1, "snpc"),
                just=rects$just, name=rects$name, gp=rects$gp, vp=rects$vp)
Error in validDetails.roundrect(x) : 
  'x', 'y', 'width', and 'height' must have length 1
rounded_rects <- roundrectGrob(x=rects$x[[1]], y=rects$y[[1]], width=rects$width[[1]], height=rects$height[[1]],
                r=unit(0.1, "snpc"),
                just=rects$just, name=rects$name, gp=rects$gp, vp=rects$vp)
gg$grobs[[6]]$children[[3]] <- rounded_rects
cowplot::plot_grid(gg)
rounded_rects <- lapply(1:n, function(i) roundrectGrob(x=rects$x[[i]], y=rects$y[[i]], width=rects$width[[i]], height=rects$height[[i]],
                                                       r=unit(0.1, "snpc"),
                                                       just=rects$just, name=rects$name, gp=rects$gp, vp=rects$vp))