rama
April 3, 2021, 10:57am
1
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?
Why reprex?
Getting unstuck is hard. Your first step here is usually to create a reprex, or reproducible example. The goal of a reprex is to package your code, and information about your problem so that others can run it and feel your pain. Then, hopefully, folks can more easily provide a solution.
What's in a Reproducible Example?
Parts of a reproducible example:
background information - Describe what you are trying to do. What have you already done?
complete set up - include any library() calls and data to reproduce your issue.
data for a reprex: Here's a discussion on setting up data for a reprex
make it run - include the minimal code required to reproduce your error on the data…
rama
April 3, 2021, 12:51pm
3
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)
2 Likes
system
Closed
April 10, 2021, 9:21pm
5
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.