【问题标题】:Italics within plotmath expression cannot be rendered bold in ggplotplotmath 表达式中的斜体不能在 ggplot 中呈现粗体
【发布时间】:2018-10-15 06:19:23
【问题描述】:

根据之前的帖子,我研究了如何使用expression() 将字符串中的字符串变为斜体,而字符串的其余部分保持非斜体。问题是element_text(face = "bold") 不适用于expression() 中的字符串。

ggplot(iris, aes(x = Sepal.Width)) + 
       geom_histogram(bins = 10) + 
       ylab(expression(paste("% of group ", italic("n")))) + 
       xlab("Actual Treatment") + 
       theme(axis.title.x = element_text(face = "bold"),
             axis.title.y = element_text(face = "bold"))

为了解决这个问题,我将expression() 包裹在bold() 中,就像这样

ggplot(iris, aes(x = Sepal.Width)) + 
       geom_histogram(bins = 10) + 
       ylab(expression(bold(paste("% of group ", italic("n"))))) + 
       xlab("Actual Treatment") + 
       theme(axis.title.x = element_text(face = "bold"))

但是斜体的 n 仍然是非粗体的。有什么想法吗?

【问题讨论】:

    标签: r ggplot2 plotmath


    【解决方案1】:
    expression(bold("% of group ")*bolditalic("n"))
    

    【讨论】:

    • 谢谢。 * 有什么作用?
    【解决方案2】:
    ggplot(iris, aes(x = Sepal.Width)) + 
    geom_histogram(bins = 10) + 
    labs(y=expression(bold(paste("% of group ", bolditalic("n"))),
    x="Actual Treatment"))+
    theme(axis.title.x = element_text(face = "bold"))
    

    【讨论】:

    • 请不要只发布代码作为答案,还要解释您的代码的作用以及它如何解决问题的问题。带有解释的答案通常更有帮助,质量更高,更有可能吸引投票。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-14
    • 2019-10-22
    • 2016-01-02
    • 2019-03-18
    • 1970-01-01
    • 2022-08-23
    相关资源
    最近更新 更多