在R中的箱图中更改组标签的子集的颜色 [英] Change the color of a subset of group labels in a boxplot in R

查看:78
本文介绍了在R中的箱图中更改组标签的子集的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改简单箱形图中标签的子集的颜色?例如,在X轴上,我有"3","4"和"5"组,而我只想更改"4"组标签的颜色.

How do I change the color of only a subset of labels in a simple boxplot? For example, on the X-axis I have groups "3", "4", and "5", and I only want to change the color of the "4" group label.

使用col ="red"更改框图本身的颜色很容易,甚至使用border ="red"更改框图的边框也很容易,但是我找不到任何有关更改标签的参考.

It's easy to change the color of the boxplot itself with the col="red", or even the border of the boxplot with border="red", but I cannot find any reference to changing JUST the label.

示例: boxplot(mtcars $ hp〜mtcars $ gear)

Example: boxplot(mtcars$hp~mtcars$gear)

谢谢!

推荐答案

您也可以尝试mtext:

b <- boxplot(count ~ spray, data = InsectSprays, col = "lightgray", axes = FALSE)
axis(2); axis(1, labels = NA); box()
mtext(b$names, at = 1:length(b$names), side = 1, line = 1, 
      col = ifelse(b$names == "B", "red", "black"))

这篇关于在R中的箱图中更改组标签的子集的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆