Unable to change size on axis in ggplot

Hi,
I have a following problem. I want to change the size of labels in my ggplot. See picture bellow:

I read the documentation (theme function - RDocumentation) and I tried

theme(axis.text=element_text(size=20),
 axis.title=element_text(size=20),
 axis.ticks=element_text(size=20),
 axis.line=element_text(size=20))

but it did not work. What do I do wrong please? Thanks a lot.

Reprex here:

require(forcats)
require(ggplot2)
require(dplyr)

df <- data.frame(x = c("A", "B", "C", "D", "E"),
                      estimate = c(-0.03, 0.06 , 0.15 , -0.003, 0.01 ),
                      CI_up = c(-0.03 + 0.06*1.96, 0.06 + 0.02*1.96, 0.15 + 0.04*1.96, -0.003 + 0.06*1.96 , 0.01 + 0.01*1.96) ,
                      CI_down = c(-0.03 - 0.06*1.96, 0.06 - 0.02*1.96, 0.15 - 0.04*1.96, -0.003 - 0.06*1.96 , 0.01 - 0.01*1.96) )




df %>%
  mutate(x = fct_reorder(x, desc(estimate))) %>%
  ggplot(aes(x = x, y = estimate)) +
  geom_point(size = 4) +
  geom_errorbar(aes(ymax = CI_up, ymin = CI_down)) + 
  labs(x = "My X axis", y = "My Y axis") +
  theme(axis.text=element_text(size=555),
        axis.title=element_text(size=14)) +
  geom_hline(yintercept = 0) +
  theme_bw()

Can you provide a reproducible example?

see above edited question

The theme_bw() should be near the top. In your code, it is overwriting your custom text sizes. Wheras below, the theme is set, then the custom text sizes overwrite it.

df %>%
  mutate(x = fct_reorder(x, desc(estimate))) %>%
  ggplot(aes(x = x, y = estimate)) +
  theme_bw() + # move this up, the theme overwrites some of the settings. 
  geom_point(size = 4) +
  geom_errorbar(aes(ymax = CI_up, ymin = CI_down)) + 
  labs(x = "My X axis", y = "My Y axis") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=14)) +
  geom_hline(yintercept = 0) 

image

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.