首页 > 解决方案 > 摆脱ggplot中面板上的边框?

问题描述

我正在尝试删除此数据的边界,即。这是我当前的代码:

ggplot(data = GDP, aes(x=year, y=gdp_percap/1e3, fill=continent)) + 
geom_col() + 
 facet_wrap(~continent, ncol=2) + 
 ylab("GDP") + 
  theme_minimal() + 
  theme(legend.position = "none",
  panel.background = element_rect(fill=NA, color="gray50"),
  panel.grid.major = element_blank(),
  panel.grid.minor = element_blank(),
  panel.border = element_blank())
  strip.background = element_rect(fill=NA, color=NA) +
scale_y_continuous(expand = expand_scale(mult = c(0, 0.05)),
breaks = seq(0,200,100),limits=c(0,NA)) +
scale_x_continuous(expand = c(0,0),
breaks = seq(1950,2000,20))

GDP数据

在此处输入图像描述

标签: ggplot2

解决方案


我相信边界是指所有方面的框?在这种情况下,请注意您指定让每个构面都有一个透明的背景矩形,其中包含:panel.background = element_rect(fill=NA, color="gray50")

将其更改为此,您将删除所有这些边框:

panel.background = element_blank()

如果您仍然需要轴线(只要您有轴标签,则为 X 和 Y),请在以下内容中添加theme(...)

axis.line = element_line(color='black')

有关格式化的更多信息,此资源非常有用。


推荐阅读