Reputation: 754
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))
How can I colour the label above? (and only that one)
Upvotes: 7
Views: 3767
Reputation: 43334
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
Upvotes: 13