R在基本图形图中为y轴值着色,每个图具有不同的颜色

时间:2018-01-26 22:18:56

标签: r

我试图在基本图形图中为每个颜色不同的颜色设置y轴值,但我无法弄清楚如何做到这一点。 类似的东西:

 plot(1:5,col.ylabels= c("red","orange","yellow","green","blue"))

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您需要取消初始轴值并替换为自定义text

plot(1:5, col = c("red", "orange", "yellow", "green", "blue"), yaxt = 'n')
lablist <- as.vector(c(1:5))
text(par("usr")[1] - 0.4, 1:5 + 0.25,
     labels = lablist, pos = 1, xpd = TRUE, 
     col = c("red","orange","yellow","green","blue"))

我通过引用?text处的文档为https://stats.idre.ucla.edu/r/faq/how-can-i-change-the-angle-of-the-value-labels-on-my-axes/处的示例添加了颜色。

enter image description here