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

如何去除ggplot2柱状图(Bar Plot)中的内部线条?

解决无内部线条柱状图的问题

你代码里的color = 'red'是给柱状图加了红色边框线条,这就是你看到的那些“内部线条”(实际是柱子的轮廓线)。要去掉这些线条,两种简单方法:

方法1:删掉color参数

直接移除color = 'red',ggplot默认不会显示边框:

library(ggplot2)

ggplot(data = Datoshoja1, aes(x = `AreaName`, y = `1990.0`)) + 
  geom_bar(stat="identity", fill = 'darkred') +
  labs(title= 'Inmigrantes en EEUU año 1990', x = '', y = 'Cantidad de inmigrantes')

方法2:设置color = NA

如果想保留参数结构,把color设为NA就能隐藏边框:

library(ggplot2)

ggplot(data = Datoshoja1, aes(x = `AreaName`, y = `1990.0`)) + 
  geom_bar(stat="identity", color = NA, fill = 'darkred') +
  labs(title= 'Inmigrantes en EEUU año 1990', x = '', y = 'Cantidad de inmigrantes')

两种方法都能让柱状图没有额外的轮廓线条,达到你要的无内部线条效果。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 03:15:38