r - Default text color of axes in ggplot
问题描述
I want to change the color of the text of the x-axis in ggplot if a condition is met. No problem but for that, I have to know which is the default color of the x-axis in theme_minimal()
. I looked in the source code, that leaded me to theme_bw()
which lead me to theme_grey()
which you can find here: https://github.com/tidyverse/ggplot2/blob/master/R/theme-defaults.r
I see the declaration of many colors but not the one of the x-axis
?
解决方案
You can use ggplot2
package's calc_element()
to figure out what you want. In this case, the default font colour for x-axis text is "grey30":
> calc_element("axis.text.x", theme_minimal())
List of 11
$ family : chr ""
$ face : chr "plain"
$ colour : chr "grey30"
$ size : num 8.8
$ hjust : num 0.5
$ vjust : num 1
$ angle : num 0
$ lineheight : num 0.9
$ margin : 'margin' num [1:4] 2.2pt 0pt 0pt 0pt
..- attr(*, "valid.unit")= int 8
..- attr(*, "unit")= chr "pt"
$ debug : logi FALSE
$ inherit.blank: logi TRUE
- attr(*, "class")= chr [1:2] "element_text" "element"
推荐阅读
- arrays - 这个数组是未定义的,但为什么呢?
- javascript - 如何让用户单击颜色以成为更改单击时 svg 对象填充的函数
- c# - 在 Xamarin 表单中,如何使选择器中的选定选项在其他选择器中不可见?
- javascript - 拖动图像下方的元素
- c# - 如何在运行时更改自定义属性的属性?
- sql-server - 使用 CONVERT() 向数字添加一美元,但仍按数字排序
- vb.net - 在使用复选框插入之前检查另一个datagridview中是否已经存在datagridview
- python - Django Rest Framework - 有条件地使序列化程序的字段成为必需或不使用其他字段值
- reactjs - 用酶 mocha chai 和 sinon 测试 React 组件
- regex - REGEX 从字符串中获取最后 6 位数字