本文介绍了删除ggplot周围的彩色边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将ggplots
添加到viewports
. ggplot
和viewport
都具有相同的背景颜色.我的问题是我的ggplots
周围有一个白色矩形,我似乎无法找到使用theme
删除它的选项.有什么想法吗?
I am adding ggplots
to viewports
. Both ggplot
and viewport
has the same background colour. My problem is that I have a white rectangle surrounding my ggplots
and I dont seem to be able to find the option to remove it using theme
. Any ideas?
library(grid)
library(ggplot2)
Pie_chart <- ggplot(df , aes(x = "", y = prop_1, fill = rank) ) +
geom_bar(stat="identity", width=2) +
coord_polar("y", start = 0) +
labs(x = NULL, y = NULL, fill = NULL, title = "") +
theme(axis.line = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
legend.position="none")+
theme(plot.margin = unit(c(0.0, 0.0, 0.0, 0.0), "cm"),
plot.background = element_rect(fill = "blue"),
panel.background = element_rect(fill = "blue"))
lower_section_viewport <- viewport(
layout = grid.layout(nrow = 1, ncol = 2,
widths = unit(c(2, 1), c("null", "null"))),
name = "lower_section")
grid.newpage()
pushViewport(lower_section_viewport)
grid.rect(gp = gpar(fill = "blue", col = "blue" ))
pushViewport(viewport(layout.pos.row = 1, layout.pos.col = 2))
print(Pie_chart, vp = current.viewport())
upViewport()
数据:
> dput(df)
structure(list(a = structure(1:11, .Label = c("0-Management",
"1-Business, finance & administration", "2-Natural and applied sciences",
"3-Health occupations", "4-Occupations in education", "5-Art & culture",
"6-Sales ans service occupations", "7-Trade & Transport", "8-Agriculture",
"9-Manufacturing", "X-Not Identified"), class = "factor"), b = c(75,
92, 64, 61, 90, 51, 77, 78, 94, 98, 96), prop = c("9%", "11%",
"7%", "7%", "10%", "6%", "9%", "9%", "11%", "11%", "11%"), prop_1 = c(9,
11, 7, 7, 10, 6, 9, 9, 11, 11, 11), rank = c("0", "1", "2", "3",
"4", "5", "6", "7", "8", "9", "X")), class = "data.frame", row.names = c(NA,
-11L))
推荐答案
您要查找的是theme(plot.backround = ... )
中的参数colour = NA
.
It's the argument colour = NA
in theme(plot.backround = ... )
you are looking for.
Pie_chart <- ggplot(df , aes(x = "", y = prop_1, fill = rank) ) +
geom_bar(stat="identity", width=2) +
coord_polar("y", start = 0) +
labs(x = NULL, y = NULL, fill = NULL, title = "") +
theme(axis.line = element_blank(), axis.text = element_blank(), axis.ticks = element_blank(), legend.position="none")+
theme(plot.margin = unit(c(0.0, 0.0, 0.0, 0.0), "cm"),
plot.background = element_rect(fill = "blue",
colour = NA), # here it is
panel.background = element_rect(fill = "blue"))
...
这篇关于删除ggplot周围的彩色边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!