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

R语言中用webr绘制的嵌套饼图为何有边框?如何去除?

去除webr包PieDonut嵌套饼图的边框

webr包的PieDonut函数基于ggplot2实现,图表默认带边框,你可以通过叠加ggplot2的主题设置来移除边框。同时注意你原代码里有几处语法错误(管道符%>%写漏了一半),以下是修正并添加去边框设置的完整代码:

library(tidyverse)
library(webr)

g <- data.frame(
  animal = c("Alpaca", "Donkey", "Dog ", "Cat"),
  A = c(50,215,15,21),
  B = c(22,55,1,5),
  C = c(58,1,5,15)
)

l_g <- g %>%
  pivot_longer(cols = -"animal", names_to = "Condition", values_to = "value")

P_ge <- l_g %>% 
  group_by(Condition, animal) %>%
  summarise(n = sum(value), .groups = "drop")

PieDonut(P_ge, aes(Condition, animal, count = n),
         labelposition = 1, 
         r0 = 0.5, 
         r1 = 0.95, 
         explode = 2, explodeDonut = TRUE) +
  theme(
    panel.border = element_blank(),  # 移除面板边框
    plot.border = element_blank()    # 移除整个图表的外边框
  )

关键说明:

  • PieDonut返回的是标准ggplot2对象,因此可以直接用+叠加theme()修改样式。
  • panel.border控制绘图区域的边框,plot.border控制整个图表容器的边框,两者都设为element_blank()即可完全移除边框。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 09:51:07