Home > Enterprise >  How to add italic values in ggplot
How to add italic values in ggplot

Time:10-09

I have the following df:

df <- data.frame(Species = c("C. lupus", "C. latrans", "C. lupaster"),
                 pi = c('0.03', '0.04', '0.02'))

and I made a plot with ggplot

df %>%
  mutate(Species= fct_reorder(Species, pi )) %>%
  ggplot(aes(x=Species, y=pi))  
  geom_bar(stat="identity", fill="#f68060", alpha=.6, width=.4)  
  coord_flip()  
  xlab("")  
  theme_bw()  
  ylab("Nucleotide diversity (π)")

How can I write the species names in italic?

Thanks!

CodePudding user response:

Just add theme(axis.text.y = element_text(face = 3)):

df %>%
  mutate(Species= fct_reorder(Species, pi )) %>%
  ggplot(aes(x=Species, y=pi))  
  geom_bar(stat="identity", fill="#f68060", alpha=.6, width=.4)  
  coord_flip()  
  xlab("")  
  theme_bw()  
  theme(axis.text.y = element_text(face = 3))  
  ylab("Nucleotide diversity (π)")

enter image description here

  • Related