gpt4 book ai didi

r - 更改 ggplot2 中特定刻度的颜色

转载 作者:行者123 更新时间:2023-12-04 09:48:45 24 4
gpt4 key购买 nike

假设我使用 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))

enter image description here

如何给上面的标签着色? (而且只有那个)

最佳答案

您需要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')))

渲染

plot with green tick label

关于r - 更改 ggplot2 中特定刻度的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34841470/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com