在保留其大小的同时将表达式更改为ggplot2中的粗体

Indrajeet帕蒂

我想在ggplot2绘图轴上显示一个表达式,在此我想同时更改sizeface测试轴:

使用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

瑞·巴拉达斯(Rui Barradas)

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))

enter image description here

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))

enter image description here

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

ggplot2中的数学表达式注释问题

ggplot2构面标签中的表达式

将行更改为ggplot2的图例中的虚线

将单个分类 geom_point 间隔标签更改为希腊表达式 ggplot

使用R中的facet_grid的ggplot2 boxplot中的表达式分别更改x标签

如何将统计测试的结果作为 ggplot2 facet 中的 plotmath 表达式包含在内

将列的默认值更改为表达式

将 If 语句链更改为 Switch 表达式

如何使用IntelliJ快捷方式将Java中的Runnable更改为lambda表达式

在ggplot2表达式中混合使用表达式,纯文本和换行符

将条件布尔表达式或函数本身更改为正常的相等表达式

遍历C ++表达式树以将表达式更改为NNF

ggplot2:将多行图例标题与数学表达式对齐

ggplot2 facet_wrap与数学表达式

R / ggplot2:评估表达式内的对象

ggplot2 绘制数学表达式

评估ggplot2内部的表达式

如果将小写的正则表达式更改为\ n,则将其更改为空格

在ggplot2和facet_wrap中具有表达式的as_labeller

使用“表达式”在ggplot2轴文本中制作特殊字符时的文本对齐

通过表达式生成时如何在ggplot2中对齐标题和字幕

刻度标记标签ggplot2中的数学表达式

在ggplot2字幕的plotmath表达式中包括条件元素

ggplot2中具有数学运算符的Plotmath表达式

使用多个aes()参数在ggplot2表达式中设置行的颜色

在ggplot2输出中组合希腊语和表达式

使用ggplot2中的正则表达式为变量分配特定颜色

从R中的乳胶表达式向量创建ggplot2图例

使用checkboxInput将ggplot2更改为可绘制