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

如何在R语言的ggplot环形图中移除坐标轴标签

解决ggplot环形图多余坐标轴标签的问题

我看了你的环形图代码,那些左侧的2.0...4.0标签是径向(x轴)的刻度文本,而环形周围的0.00/1...0.75是周向(y轴)的刻度文本。要移除它们,只需要在theme()里明确把这两个轴的文本都设置为空即可。

修改关键部分

你原来的代码里有一行设置轴文本的代码:

axis.text = element_text(color=txt_col, size=8, hjust = 0.4)

把这行替换成:

axis.text.x = element_blank(),
axis.text.y = element_blank()

这样就能彻底隐藏所有轴的刻度文本,只保留你需要的自定义标签。

修改后的完整代码

ggplot(region_average, aes(ymax=ymax, ymin=ymin, xmax=4, xmin=3, fill=state_code)) + 
  geom_rect() + 
  geom_label_repel(x=3.5, aes(y=labelPosition, label=label), size=3) + 
  scale_fill_brewer(palette=4) + 
  coord_polar(theta="y") + 
  xlim(c(2, 4)) + 
  theme(
    legend.position = "none", 
    panel.grid = element_blank(), 
    panel.background = element_blank(), 
    axis.ticks = element_blank(),
    axis.title.y = element_blank(), 
    axis.title.x = element_blank(),
    axis.text.x = element_blank(),  # 隐藏径向x轴标签
    axis.text.y = element_blank(),  # 隐藏周向y轴标签
    axis.title.y.left = element_blank(), 
    panel.background = element_rect(fill = bg, color = bg), 
    panel.grid.major=element_blank(), 
    panel.grid.minor=element_blank(), 
    panel.border=element_blank(), 
    plot.title = element_text(hjust=0,size=24, color=txt_col,lineheight=.8, face="bold", margin=margin(0,0,0,0)), 
    plot.subtitle = element_text(hjust=0,size=14, color=txt_col, margin=margin(5,0,20,0)), 
    plot.title.position = "plot", 
    plot.caption = element_text(hjust=.5, margin=margin(20,0,0,0), size=8, color=txt_col, face="bold"), 
    plot.background = element_rect(color=bg, fill=bg), 
    plot.margin = margin(30,30,30,30), 
    legend.title = element_blank()
  ) + 
  labs(title = "Regional Distribution of Ad Reach", subtitle = "Overall distribution for all ads studied")

小提示

你原来的代码里重复设置了panel.grid和legend.position,可以适当清理一下,让代码更简洁,不过这不会影响最终图表的显示效果。

内容的提问来源于stack exchange,提问作者piñatabreaker

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.28 22:27:40