6

Say I created custom ticks with ggplot using:

library(ggplot2)

ticksX <- data.frame (t = c(0,0.25,0.5,0.75,1))
ticksY <- data.frame (t = c(0,0.25,0.3868,0.5,0.75,1))

ggplot(data=data.frame()) +
scale_y_continuous(breaks=c(ticksY$t),limits=c(0,1), 
                            labels=expression(0,0.25,'Colour this one.'
                                              ,0.5,0.75,1)) +
scale_x_continuous(breaks=c(ticksX$t),limits=c(0,1),
                     labels=expression(0,0.25,0.5,0.75,1))

enter image description here

How can I colour the label above? (and only that one)

Michael Harper
  • 14,721
  • 2
  • 60
  • 84
user191919
  • 724
  • 1
  • 9
  • 27

1 Answers1

12

You need to theme axis.text.y, and pass colour a vector with a color for each label.

ggplot(data=data.frame()) +
  scale_y_continuous(breaks=c(ticksY$t),limits=c(0,1), 
                     labels=expression(0,0.25,'Colour this one.',0.5,0.75,1)) +
  scale_x_continuous(breaks=c(ticksX$t),limits=c(0,1), labels=expression(0,0.25,0.5,0.75,1)) +
  theme(axis.text.y = element_text(colour = c('black', 'black','green', 'black', 'black', 'black')))

renders

plot with green tick label

alistaire
  • 42,459
  • 4
  • 77
  • 117