13

I have tried

... + xlab("New label", colour="darkgrey")

and

... + xlab("New label", color="darkgrey")

But it says this argument is unused. I look into ?xlab, but it doesn't include any color parameter. Is it possible to change it? How?

João Daniel
  • 8,696
  • 11
  • 41
  • 65
  • Related question (may be useful to have a cross-link): https://stackoverflow.com/questions/24075446/how-to-get-axis-ticks-labels-with-different-colors-within-a-single-axis-for-a-gg – PatrickT Apr 20 '18 at 12:01

2 Answers2

37

Since ggplot2 0.9.2, the syntax has become:

dat <- data.frame(x = 1:5,y = 1:5)
p + theme(axis.title.x = element_text(colour = "red"),
          axis.title.y = element_text(colour = "blue"))

The tidyverse page is a good starting point for learning about all the options.

Note that the old syntax based on opts has been deprecated. There is detailed transition guide for updating your code.

PatrickT
  • 10,037
  • 9
  • 76
  • 111
joran
  • 169,992
  • 32
  • 429
  • 468
  • @PatrickT Thanks! I should be better about updating my answers, but there's only so much time in the day. In the future, feel free to simply suggest an edit to my answer directly with the updated syntax, I'll get a notification and can approve it directly. – joran Apr 02 '13 at 22:23
  • @PatrickT: after 5.5 Years I have seen that p + theme(axis.title.x = element_text(colour = "red"), axis.title.y = element_text(colour = "blue")) this works. – smurfit89 Dec 26 '18 at 14:55
1

This changes both the x and y axis:

theme(text=element_text(color="red"))

This also changes the labels of the ticks:

theme(text=element_text(color="red"),axis.text=element_text(color="blue"))
nisetama
  • 7,764
  • 1
  • 34
  • 21