调整ggplot中的图形大小 - 保持比例,字体大小等

时间:2017-08-04 15:43:54

标签: r ggplot2

我是ggplot的新手,但我设法做了一个我非常满意的条形图。但是,我需要把它做得更小,以便整齐地放在纸上。我无法弄清楚如何调整它的大小而不搞砸比例,字体大小等。 有什么想法吗?

这是调整大小之前的情节:

plot before resizing

此后它看起来很可怕:

plot after resizing

这是我使用的代码。非常感谢!

    #creating a data frame

    df <- data.frame("DV"=runif(100), factor1=1:100, factor2=1:100)
    df$factor1[1:50] <- "A"
    df$factor1[51:100] <- "B"
    df$factor2[1:25] <- "X"
    df$factor2[51:75] <- "X"
    df$factor2[26:50] <- "Y"
    df$factor2[76:100] <- "Y"

    plot <- ggplot(df, aes(factor1, DV, fill=factor2)) + 
      stat_summary(fun.y = "mean", geom="bar", position="dodge") +
      stat_summary(fun.data = mean_cl_normal, geom = "errorbar", 
      position = position_dodge(width=0.9), width=0.2) +
      theme_bw()+
      labs(title="Example plot", x="x", y="y", fill="factor2") +
      theme(plot.title = element_text(hjust = 0.5, size=11)) +
      scale_fill_manual(breaks=c("X", "Y"), labels=c("level X", "level Y"), values=c("#D55E00", "#56B4E9")) +
      scale_x_discrete(breaks=c("A", "B"), labels=c("level A", "levelB")) +
      theme(text=element_text(size=11))
      plot

      ggsave("plot1.eps") #saves a 7x7 image

      ggsave("plot2.eps", height=3.5, width=3.5) #keeping with the dimensions and reducing size, looks horrible

0 个答案:

没有答案