简体   繁体   中英

Changing font size on collated plot

I want to make the font bigger on the axes on a collated plot. I'd like both the axes on the collated plot, as well as the axes on each individual plot to be bigger. Is there an easy way to do this without individually going into each of the plots I've collated together and changing the font size- for example, can I add anything to the plot_grid() function to do this? Code for context is included below.

# Make Figure 4.
# Flanker.
flanker.Training <- ggplot(data=correlations, aes(x=`Flanker.Con-Incon`, y=Training.ACC)) + 
  geom_smooth(method = "lm", color="#CEB888") +
  geom_point() +
  theme_cowplot(font_size=16) +
  scale_x_continuous(name="Flanker") +
  scale_y_continuous(name="p(Correct)", limits=c(0.4, 1)) +
  theme(legend.position="none") +
  labs(title="Training") +
  theme(panel.grid.major.y = element_line(colour="grey"))
flanker.Training

flanker.Pretest <- ggplot(data=correlations, aes(x=`Flanker.Con-Incon`, y=`Pre-test.ACC`)) + 
  geom_smooth(method = "lm", color="#CEB888") +
  geom_point() +
  theme_cowplot(font_size=16) +
  scale_x_continuous(name="Flanker") +
  scale_y_continuous(name="p(Correct)", limits=c(0.4, 1)) +
  theme(legend.position="none") +
  labs(title="Pre-test") +
  theme(panel.grid.major.y = element_line(colour="grey"))
flanker.Pretest

flanker.Posttest <- ggplot(data=correlations, aes(x=`Flanker.Con-Incon`, y=`Post-test.ACC`)) + 
  geom_smooth(method = "lm", color="#CEB888") +
  geom_point() +
  theme_cowplot(font_size=16) +
  scale_x_continuous(name="Flanker") +
  scale_y_continuous(name="p(Correct)", limits=c(0.4, 1)) +
  theme(legend.position="none") +
  labs(title="Post-test") +
  theme(panel.grid.major.y = element_line(colour="grey"))
flanker.Posttest

flanker.PostPre <- ggplot(data=correlations, aes(x=`Flanker.Con-Incon`, y=`Post-Pre.ACC`)) + 
  geom_smooth(method = "lm", color="#CEB888") +
  geom_point() +
  theme_cowplot(font_size=16) +
  scale_x_continuous(name="Flanker") +
  scale_y_continuous(name=expression(Delta~p(Correct))) +
  theme(legend.position="none") +
  labs(title="Learning") +
  theme(panel.grid.major.y = element_line(colour="grey"))
flanker.PostPre

# Pitch.
pitch.Training <- ggplot(data=correlations, aes(x=Pitch.Dprime, y=Training.ACC)) + 
  geom_smooth(method = "lm", color="#004369") +
  geom_point() +
  theme_cowplot(font_size=16) +
  scale_x_continuous(name="Pitch perception (d')", limits=c(-0.6, 4.2)) +
  scale_y_continuous(name="p(Correct)", limits=c(0.4, 1)) +
  theme(legend.position="none") +
  theme(panel.grid.major.y = element_line(colour="grey"))
pitch.Training

pitch.Pretest <- ggplot(data=correlations, aes(x=Pitch.Dprime, y=`Pre-test.ACC`)) + 
  geom_smooth(method = "lm", color="#004369") +
  geom_point() +
  theme_cowplot(font_size=16) +
  scale_x_continuous(name="Pitch perception (d')", limits=c(-0.6, 4.2)) +
  scale_y_continuous(name="p(Correct)", limits=c(0.4, 1)) +
  theme(legend.position="none") +
  theme(panel.grid.major.y = element_line(colour="grey"))
pitch.Pretest

pitch.Posttest <- ggplot(data=correlations, aes(x=Pitch.Dprime, y=`Post-test.ACC`)) + 
  geom_smooth(method = "lm", color="#004369") +
  geom_point() +
  theme_cowplot(font_size=16) +
  scale_x_continuous(name="Pitch perception (d')", limits=c(-0.6, 4.2)) +
  scale_y_continuous(name="p(Correct)", limits=c(0.4, 1)) +
  theme(legend.position="none") +
  theme(panel.grid.major.y = element_line(colour="grey"))
pitch.Posttest

pitch.PostPre <- ggplot(data=correlations, aes(x=Pitch.Dprime, y=`Post-Pre.ACC`)) + 
  geom_smooth(method = "lm", color="#004369") +
  geom_point() +
  theme_cowplot(font_size=16) +
  scale_x_continuous(name="Pitch perception (d')", limits=c(-0.6, 4.2)) +
  scale_y_continuous(name=expression(Delta~p(Correct))) +
  theme(legend.position="none") +
  theme(panel.grid.major.y = element_line(colour="grey"))
pitch.PostPre

# Identification slope.
id.Training <- ggplot(data=correlations, aes(x=ID.Slope, y=Training.ACC)) + 
  geom_smooth(method = "lm", color="#BAA892") +
  geom_point() +
  theme_cowplot(font_size=16) +
  scale_x_continuous(name="Identification slope", limits=c(0, 0.3)) +
  scale_y_continuous(name="p(Correct)", limits=c(0.4, 1)) +
  theme(legend.position="none") +
  theme(panel.grid.major.y = element_line(colour="grey"))
id.Training

id.Pretest <- ggplot(data=correlations, aes(x=ID.Slope, y=`Pre-test.ACC`)) + 
  geom_smooth(method = "lm", color="#BAA892") +
  geom_point() +
  theme_cowplot(font_size=16) +
  scale_x_continuous(name="Identification slope", limits=c(0, 0.3)) +
  scale_y_continuous(name="p(Correct)", limits=c(0.4, 1)) +
  theme(legend.position="none") +
  theme(panel.grid.major.y = element_line(colour="grey"))
id.Pretest

id.Posttest <- ggplot(data=correlations, aes(x=ID.Slope, y=`Post-test.ACC`)) + 
  geom_smooth(method = "lm", color="#BAA892") +
  geom_point() +
  theme_cowplot(font_size=16) +
  scale_x_continuous(name="Identification slope", limits=c(0, 0.3)) +
  scale_y_continuous(name="p(Correct)", limits=c(0.4, 1)) +
  theme(legend.position="none") +
  theme(panel.grid.major.y = element_line(colour="grey"))
id.Posttest

id.PostPre <- ggplot(data=correlations, aes(x=ID.Slope, y=`Post-Pre.ACC`)) + 
  geom_smooth(method = "lm", color="#BAA892") +
  geom_point() +
  theme_cowplot(font_size=16) +
  scale_x_continuous(name="Identification slope", limits=c(0, 0.3)) +
  scale_y_continuous(name=expression(Delta~p(Correct))) +
  theme(legend.position="none") +
  theme(panel.grid.major.y = element_line(colour="grey"))
id.PostPre

# Within-category discrimination.
discrimination.Training <- ggplot(data=correlations, aes(x=Discrimination.Dprime, y=Training.ACC)) + 
  geom_smooth(method = "lm", color="#79AFBA") +
  geom_point() +
  theme_cowplot(font_size=16) +
  scale_x_continuous(name="Discrimination (d')", limits=c(-0.6, 4.2)) +
  scale_y_continuous(name="p(Correct)", limits=c(0.4, 1)) +
  theme(legend.position="none") +
  theme(panel.grid.major.y = element_line(colour="grey"))
discrimination.Training

discrimination.Pretest <- ggplot(data=correlations, aes(x=Discrimination.Dprime, y=`Pre-test.ACC`)) + 
  geom_smooth(method = "lm", color="#79AFBA") +
  geom_point() +
  theme_cowplot(font_size=16) +
  scale_x_continuous(name="Discrimination (d')", limits=c(-0.6, 4.2)) +
  scale_y_continuous(name="p(Correct)", limits=c(0.4, 1)) +
  theme(legend.position="none") +
  theme(panel.grid.major.y = element_line(colour="grey"))
discrimination.Pretest

discrimination.Posttest <- ggplot(data=correlations, aes(x=Discrimination.Dprime, y=`Post-test.ACC`)) + 
  geom_smooth(method = "lm", color="#79AFBA") +
  geom_point() +
  theme_cowplot(font_size=16) +
  scale_x_continuous(name="Discrimination (d')", limits=c(-0.6, 4.2)) +
  scale_y_continuous(name="p(Correct)", limits=c(0.4, 1)) +
  theme(legend.position="none") +
  theme(panel.grid.major.y = element_line(colour="grey"))
discrimination.Posttest

discrimination.PostPre <- ggplot(data=correlations, aes(x=Discrimination.Dprime, y=`Post-Pre.ACC`)) + 
  geom_smooth(method = "lm", color="#79AFBA") +
  geom_point() +
  theme_cowplot(font_size=16) +
  scale_x_continuous(name="Discrimination (d')", limits=c(-0.6, 4.2)) +
  scale_y_continuous(name=expression(Delta~p(Correct))) +
  theme(legend.position="none") +
  theme(panel.grid.major.y = element_line(colour="grey"))
discrimination.PostPre

# Collate to columns.
F4.C1 <- plot_grid(flanker.Training, pitch.Training, id.Training, discrimination.Training,
                   align="v", ncol=1,
                   rel_heights = c(0.28, 0.24, 0.24, 0.24))
F4.C1

F4.C2 <- plot_grid(flanker.Pretest, pitch.Pretest, id.Pretest, discrimination.Pretest,
                   align="v", ncol=1,
                   rel_heights = c(0.28, 0.24, 0.24, 0.24))
F4.C2

F4.C3 <- plot_grid(flanker.Posttest, pitch.Posttest, id.Posttest, discrimination.Posttest,
                   align="v", ncol=1,
                   rel_heights = c(0.28, 0.24, 0.24, 0.24))
F4.C3

F4.C4 <- plot_grid(flanker.PostPre, pitch.PostPre, id.PostPre, discrimination.PostPre,
                   align="v", ncol=1,
                   rel_heights = c(0.28, 0.24, 0.24, 0.24))
F4.C4

# Collate/print Figure 3.
Figure4 <- plot_grid(F4.C1, F4.C2, F4.C3, F4.C4,
                     align="h", nrow=1)  
Figure4
pdf("Figure4.pdf", 16, 16, bg="transparent")
plot(Figure4)
dev.off()

If you're willing to switch to the patchwork package for plot composition, you can easily set global theme elements with the & theme(...) operation. Simplified example below.

library(patchwork)
library(ggplot2)

p <- ggplot(mpg, aes(displ, hwy)) +
  geom_point()

p + p + p + p + plot_layout(ncol = 2, nrow = 2) &
  theme(axis.text = element_text(size = rel(2)))

Created on 2021-04-21 by the reprex package (v1.0.0)

I didn't understand what you meant with 'making axes bigger', so I've ignored that bit of the question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM