假设我使用ggplot创建了自定义刻度:
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))
如何为上面的标签上色? (只有那一个)
答案 0 :(得分:8)
您需要theme
axis.text.y
,并为colour
传递一个带有每种标签颜色的矢量。
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')))
呈现