rggplot2sizeaxisbold

ggplot & bold : how can I make bold the values in the axis bold?


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


Solution

  • 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