【问题标题】:Default text color of axes in ggplotggplot中轴的默认文本颜色
【发布时间】:2019-08-22 06:47:15
【问题描述】:

如果满足条件,我想更改 ggplot 中 x 轴文本的颜色。没问题,但为此,我必须知道 theme_minimal() 中 x 轴的默认颜色。我查看了源代码,这将我带到了theme_bw(),这将我带到了theme_grey(),你可以在这里找到:https://github.com/tidyverse/ggplot2/blob/master/R/theme-defaults.r 我看到许多颜色的声明,但不是x-axis 之一?

【问题讨论】:

  • 你能告诉你至少reprex你试过什么吗?因为它对我有用,所以我可以更改 x-axis 的文本颜色。

标签: r ggplot2


【解决方案1】:

您可以使用ggplot2 包的calc_element() 来确定您想要什么。在这种情况下,x 轴文本的默认字体颜色为“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"

【讨论】:

  • 谢谢!想不出更好的答案!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-18
  • 2011-09-22
  • 2021-05-24
  • 1970-01-01
  • 2020-08-01
  • 1970-01-01
相关资源
最近更新 更多