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

如何移除ggplot2极坐标小提琴图周围的边界框?

移除ggplot2极坐标小提琴图的边界框

你遇到的边界框来自theme_light()主题默认的面板边框,只需在theme()中添加一行配置即可移除:

修改后的完整代码:

x <- matrix(runif(n=1000,-pi/2,pi/2),ncol =4 )  
df <- reshape2::melt(x)

df$Var2 <- as.factor(df$Var2)

library(ggplot2)
df |>
  ggplot(aes(
    x = Var2,
    y = value,
    fill = Var2
  )) +
  geom_violin() +
  theme_light() +
  coord_polar() +
  geom_hline(yintercept = 0) +
  guides(fill = "none") +
  theme(
    axis.text.x = element_blank(), axis.ticks.x = element_blank(),
    axis.text.y = element_blank(), axis.ticks.y = element_blank(),
    panel.border = element_blank()  # 移除面板边框的关键配置
  ) +
  labs(x = NULL, y = NULL)

补充说明

  • theme_light()自带灰色面板边框,panel.border = element_blank()会直接清除这个边框;
  • 如果需要同时移除背景网格,可以额外添加panel.grid = element_blank()。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 00:15:00