我正在尝试从ggplot2
. 我在一个waffle
上下文中工作,所以下面的可重现示例就是这种形式。
我已经按照ggplot2 中的 Remove Plot Margins 中提供的答案进行操作,但仍然得到一个奇怪的结果。我运行以下代码,并将绘图的背景设为黄色以突出显示边距。
library("waffle")
parts <- data.frame(
names = LETTERS[1:4],
vals = c(80, 30, 20, 10)
)
waffle(parts, rows = 8, xlab = "Each Square = X",legend_pos = "bottom") +
guides(fill = guide_legend(ncol=1)) +
theme(plot.margin = margin(0,0,0,0,unit = "cm"),
legend.margin = margin(b=0,unit="cm"),
plot.background = element_rect(fill="yellow"))
ggsave(file = "graphs/test.jpg")
下图是我将 jpg 粘贴到 Word 中时看到的。
黄色边框确认已正确指定边距,但在虚线内的图形周围获得白色边框。有没有办法避免这种情况?