Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot2: classic plot with black labels for x and y axis

Tags:

r

ggplot2

I am trying to plot data with a classic look and black axis labels. Yet, theme_classic has two different shades of grey for the axis tick labels and the ticks.

Using the mtcars dataset and p1 as listed in ?theme_classic I tried

 p1 + theme_classic(axis.text.x = element_text(colour="black"))

but this just works with theme not theme_classic.

Is there a way to get black axis ticks and labels without having to specify a classic theme from scratch?

like image 296
klaudia Avatar asked Oct 27 '25 05:10

klaudia


1 Answers

You need to add customizations to theme() calls after theme_classic(). Try:

p1 + theme_classic() +
  theme(
    axis.text.x = element_text(color="black"),
    axis.ticks = element_line(color = "black")
  )

The only arguments theme_***() functions typically take are base size and family related arguments. Additional customization is done through plain theme().

like image 180
Gregor Thomas Avatar answered Oct 28 '25 19:10

Gregor Thomas