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
?
Asked
Active
Viewed 2,176 times
4
-
can you show a minimum [reprex](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on what have you tried? Because it works for me, I'm able to change the text color of `x-axis`. – mnm Apr 01 '19 at 08:05
1 Answers
8
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"

Z.Lin
- 28,055
- 6
- 54
- 94