代码中我用options限定画布的大小为3x3(否则jupyter中输出图形过大),指定legend.position = c(1, 0.85),但是饼图被遮挡。使用过par(xpd=TRUE) par(mai=c(20,20,20,20)) 来设置可在画图区域外画图,但是不管用(我不确定par是否能用于ggplot2,没查到相关资料)。在Rstudio中可以通过鼠标拖动放大画布来解决,但是相应的图形也变大了,字体什么的都没有相应变大。求大神帮忙。
下面的两张图,一张是我在Rstudio中输出的结果,另外一张是在jupyter中输出的结果。
options( repr.plot.width = 3, repr.plot.height = 3, warn = -1)
x <- c("男", "女", "男", "女", "男", "女", "男", "女", "男33333333333333333", "女")
t <- table(x)
fill <- names(t)
y <- as.vector (t)
label <- paste0('(', round(y / sum(y) * 100, 1), '%)')
d <- data.frame("x", y, fill)
ggplot(d, aes(x = "", y = y, fill = fill)) +
geom_bar(stat = 'identity', width = 0.1) +
coord_polar(theta = 'y', direction = 1) +
labs(x = "", y = "") +
geom_text(
aes(x = 1, label = as.character(label)),
position = position_stack(reverse = F, vjust = 0.5),
size = 3,
color = "white"
) +
labs(title = "title222222222222222222222222", fill = "") +
theme(
axis.line = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
legend.key.size = unit(0.3, 'cm'),
legend.text = element_text(size = 8),
legend.position = c(1, 0.85)
)


雷达卡






京公网安备 11010802022788号







