0

I'm trying to make bold the values on the axis of a plot, but i'm failing!

I'm only finding guides to make the label of the axis bold, but it is not what I'm looking for...

do you know what is the right command?? If in the x-axis i have ( 1, 2, 3, 4), I need to have them bold or with a greater size

I have already tried

theme(axis.text = element_text(face="bold"))
theme(axis.title = element_text(face="bold")

but none of them works

this is my code

  ggplot(aes(x = reorder(`Provincia`, pcty), y = value, fill = name)) +
  geom_col() +
  theme(axis.text.x = element_text(face="bold", size = 15))+
  coord_flip()+
  theme_classic()+
  scale_fill_manual(values=c("#F76900","#4B0082")) +
  scale_y_continuous(breaks = seq(0,26,1))+
  geom_text(aes(label = paste0(format(round(pct1, digits =1)),"%"), y = pcty), hjust = 1, colour = "white", fontface = "bold")

and this is the plot.. I need to have the characters on the left in bold or bigger plot

io_boh
  • 193
  • 7
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Have you tried https://datavizpyr.com/how-to-make-axis-text-bold-in-ggplot2/? Are you adding the `theme()` to your plot with `+` or are you just calling it as a separate function? What exactly is the code you are running? – MrFlick Mar 24 '23 at 18:46
  • hi @MrFlick i've tried many things... i've uploaded the code and the plot... can you take a look? – io_boh Mar 24 '23 at 18:51
  • 2
    You are setting `them_classic()` which is resetting the theme. The order in which you add information to your plot matters. Move your `theme()` part to after the `theme_classic()` so those setting don't get overridden. – MrFlick Mar 24 '23 at 18:54

1 Answers1

1

When using a different theme like theme_classic, make sure your first call that theme before the theme function like this:

df = data.frame(x = c(1:4),
                y = c(1:4))
library(ggplot2)
ggplot(df, aes(x = x, y = x)) +
  geom_point() +
  theme_classic() +
  theme(axis.text.x = element_text(face="bold", size = 15))


You could use axis.text.x with element_text to make the labels bold and change their size like this:

df = data.frame(x = c(1:4),
                y = c(1:4))
library(ggplot2)
ggplot(df, aes(x = x, y = x)) +
  geom_point() +
  theme(axis.text.x = element_text(face="bold", size = 15))

Created on 2023-03-24 with reprex v2.0.2

Quinten
  • 35,235
  • 5
  • 20
  • 53
  • hi @Quinten and thank for the answer... i've tried in this way, but it doesn't work... i've uploaded the cose in the code in the question... what am I doing wrong? – io_boh Mar 24 '23 at 18:52
  • Hi @io_boh, Please see check my updated answer! You should first call `theme_classic` before the `theme` function. – Quinten Mar 24 '23 at 18:55
  • 1
    now it works! I didn't know thank! Thank you – io_boh Mar 24 '23 at 18:58