Problems altering axis label font sizes

961 views Asked by At

I have effectively a very simple question.

I am using ggplot2 code to alter the font size of axis text and labels. However, wherever I position the command, none of the changes are visible on the axes. All other commands are working, so I am getting the impression that something is 'overriding' the theme(axis.text..., axis.title...) command.

 ggplot(Cannock, aes(x=Capacity,color=CPType)) + 
   geom_histogram(fill="white",position="identity",binwidth=3,lwd=1) + 
   labs(title="Cannock Chase",x="Capacity", y = "Count") + 
   theme(axis.text=element_text(size=14), axis.title=element_text(size=16,face="bold")) + 
   facet_grid(CPType ~ .) + 
   geom_vline(data=mu1, aes(xintercept=grp.mean, color=CPType), linetype="dashed",size=1) + 
   theme_bw() + 
   theme(axis.line = element_line(colour = "black"),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    panel.border = element_blank(),
    panel.background = element_blank()) + 
   theme(legend.position="none") + 
   theme(strip.text.y = element_text(size=8, fac[![enter image description here][1]][1]e="bold"), strip.background = element_rect(colour="white", fill="white")) + 
   coord_cartesian(xlim = c(0,100)) + 
   theme(strip.background = element_blank(), strip.text = element_blank())

Any pointers for this would be greatly appreciated. Many thanks!

1

There are 1 answers

0
phalteman On

I think it might be that you've called theme_bw() after you change your axis text formatting. Any formatting that you want to change from defaults needs to be changed after calling theme_bw. Additionally, just to be a little cleaner and tighter, you can combine all of your theme arguments into one group so that it's easier to keep track of what you're changing. Does the code below solve the problem?

You also specify strip.text and strip.background twice, with different settings, which is probably not what you want to do.

ggplot(Cannock, aes(x=Capacity,color=CPType)) + 
  geom_histogram(fill="white",position="identity",binwidth=3,lwd=1) + 
  labs(title="Cannock Chase",x="Capacity", y = "Count") + 
  facet_grid(CPType ~ .) + 
  geom_vline(data=mu1, aes(xintercept=grp.mean, color=CPType), linetype="dashed",size=1) + 
  theme_bw() + 
  coord_cartesian(xlim = c(0,100)) +
  theme(axis.text=element_text(size=14), 
        axis.title=element_text(size=16,face="bold"),
        axis.line = element_line(colour = "black"),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.border = element_blank(),
        panel.background = element_blank(),
        legend.position="none",
        strip.text.y = element_text(size=8, face="bold"), 
        strip.text = element_blank(),
        strip.background = element_rect(colour="white", fill="white"),
        strip.background = element_blank())