【问题标题】:Figure text in R was suddenly turned to italicR中的图形文字突然变成斜体
【发布时间】:2020-08-11 13:45:27
【问题描述】:

我对 R 图中的文字有疑问。 我的代码是

    library("ggplot2")
ggplot(df, aes(x = class, y = Proportion)) +
geom_point(aes(color = class)) +
scale_color_viridis_d() +theme_minimal()+
theme(text=element_text(size=16,face = "plain"))

但是,图中的文字是斜体的。我添加了“face =”plain”, 但它没有用。 不知道是什么原因 我将不胜感激。

【问题讨论】:

  • 试试face = "bold"
  • 非常感谢,是的,face = "bold" 有效,但我需要常规文本。

标签: r figure


【解决方案1】:

face 参数有 4 个选项:plain、italic、bold & bold.italic。 如果你不希望图形是斜体,你可以删除 element_text 中的 face 参数或者你另一个值“bold”。

【讨论】:

  • 谢谢,是的,我删除了 element_text 中的 face 参数,但是当我改为粗体时它仍然是“斜体”,它变成了“粗体”。只有纯文本不起作用,但我需要“纯”文本。
【解决方案2】:

class(df$class) 类可能是一个因素?

 mtcars$cyl <- factor(mtcars$cyl)
    library("ggplot2")
    ggplot(mtcars, aes(x = cyl, y =mpg)) +
      geom_point(aes(color = cyl)) +
      scale_color_viridis_d() +theme_minimal()+
      theme(text=element_text(size=16,face = "plain"))

【讨论】:

  • 谢谢,是的,class(df$class) 是一个因素。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-31
  • 1970-01-01
  • 2015-02-25
相关资源
最近更新 更多