首页 > 解决方案 > 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?

标签: rggplot2

解决方案


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"

推荐阅读