修复grid.arrange中的图像大小

时间:2017-01-05 18:13:24

标签: r jupyter-notebook

我正在使用grid.arrange在Jupyter笔记本中并排绘制两个ggplots(在一行中)。当我这样做时,绘制的图像太大,绘图高度大于看起来非常糟糕的屏幕。我想修复图像的高度(比如2或3英寸)。有没有办法做到这一点?

修改

使用的代码

library(ggplot2)
library(gridExtra)

df <- data.frame(group = as.factor(c("Base", "Online", "TV",  "Print")),value = c(60, 12, 7, 6))
df_0 <- data.frame( group = as.factor(c("Base")), value = c(100))

plot_left <- ggplot(transform(transform(df, value=value/sum(value)), labPos=cumsum(value)-value/2), 
                    aes(x="", y = value, fill = group)) + geom_bar(width = 1, stat = "identity") + coord_polar(theta = "y") +
  theme_void() + labs(title = "Decompose Sales") + geom_text(aes(y=labPos, label=paste0(round(100*value, 0), "%")), size = 3)

plot_right <- ggplot(transform(transform(df_0, value=value/sum(value)), labPos=cumsum(value)-value/2), aes(x="", y = value)) +
  geom_bar(width = 1, stat = "identity") + coord_polar(theta = "y") + theme_void() +
  labs(title = "Total Sales") + geom_text(aes(y=labPos, label=paste0(round(100*value, 0), "%")), col = "orange", size = 3)

grid.arrange(plot_right+ guides(fill = "none") ,plot_left+ guides(fill = "none"), ncol=2, widths=c(3/10, 3/10))

0 个答案:

没有答案