我在文档中包含一个饼图,而其他图表在 ggplot2
中,因此我想使用 ggplot2
来保持图表的一致性。但是饼图没有延伸到边距
dat <- structure(list(y = c(0.0714285714285714,
0.0714285714285714,
0.107142857142857,
0.160714285714286,
0.25,
0.339285714285714),
x = structure(c(1L, 3L, 4L, 5L, 6L, 2L),
.Label = c("1 to 5", "6", "7", "8", "9", "10"),
class = "factor")),
class = "data.frame",
.Names = c("y", "x"), row.names = c(NA, -6L))
ggplot(dat, aes(x = factor(1), y = y, fill = factor(x))) +
geom_bar(width = 1, stat = "identity") +
coord_polar(theta = "y") +
theme_grey()
我会使用 theme_void()
;我使用 theme_grey
来说明这一点:饼图的边缘在面板中延伸得不够远。如何使饼图的直径等于(或非常接近)面板的宽度?修改 width=1
或 scale_x_discrete(expand = c(0,0))
无效。 coord_polar
的参数似乎也没有提供任何线索。
最佳答案
这实际上并没有解决您的问题,但它确实将饼图的区域扩大到大约面板的初始大小。
ggplot(dat, aes(x = factor(1), y = y, fill = factor(x))) +
geom_bar(width = 1, stat = "identity") +
coord_polar(theta = "y") +
guides(fill=guide_legend(override.aes=list(colour=NA))) +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text.x=element_blank(),
plot.margin = unit(c(-.75,-.75,-.75,-.75),"cm")
)
关于减少 ggplot2 饼图周围的边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38034560/