我想在ggplot2
绘图轴上显示一个表达式,在此我想同时更改size
和face
测试轴:
使用ggplot2::element_text
,我可以更改size
,但不能更改face
。
ggplot(mtcars, aes(cyl, mpg)) + geom_point() +
scale_x_continuous(
labels = parse(text = "widehat(mu)=='6'"),
breaks = 6
) +
ggplot2::theme(axis.text.x = ggplot2::element_text(face = "bold", size = 12))
作为建议在这里,我可以换的表达bold
,这部分工作(注意,仅6
是大胆的,而不是斜体亩),但是文本size
不会改变:
ggplot(mtcars, aes(cyl, mpg)) + geom_point() +
scale_x_continuous(
labels = parse(text = "bold(widehat(mu)=='6')"),
breaks = 6
) +
ggplot2::theme(axis.text.x = ggplot2::element_text(face = "bold", size = 12))
由reprex软件包(v1.0.0)创建于2021-02-12
有没有办法做到这一点ggplot2
呢?或将不得不使用类似的东西ggtext
?
Here is a way to make the font size vary as requested.
The .top
in the second plot's theme
seems to be a typo, remove it and the font becomes bigger.
And instead of parse
, use expression
for plotmath.
library(ggplot2)
ggplot(mtcars, aes(cyl, mpg)) + geom_point() +
scale_x_continuous(
labels = expression(bold(widehat(mu) == '6')),
breaks = 6
) +
theme(axis.text.x = element_text(face = "bold", size = 12))
Here is another one, with the axis label even bigger.
ggplot(mtcars, aes(cyl, mpg)) + geom_point() +
scale_x_continuous(
labels = expression(bold(widehat(mu) == '6')),
breaks = 6
) +
theme(axis.text.x = element_text(face = "bold", size = 24))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句