【问题标题】:Adding title to ggplot with Shiny inputs, text, and greek letters使用闪亮的输入、文本和希腊字母向 ggplot 添加标题
【发布时间】:2020-01-17 15:48:03
【问题描述】:

我想在 ggplot 中添加以下标题:

"Number of times where UK emissions of Sulphur Dioxide exceeded 10 microgrammes per metre cubed"

本题的组成部分来自:

free text = "Number of times where UK emissions of "
input$select = Sulphur Dioxide (or any other pollutant the user selects)
free text = "exceeded "
input$number = 10 (or any other integer the user selects)
formula = μg/m3 (where the 3 is superscript of m)

使用了 paste 和 expression 和 bquote 的组合,但结果不正确。

这是我上面的代码......

ggplot() + 
aes(x=year, y=cnt) +
labs(title = paste("Number of times where UK emissions of ", input$select, 
   " exceeded", input$number, expression(mu), "g/m", "^{3}"))

【问题讨论】:

  • expressionbquote 的组合到底是什么样的?如果您提供某种reproducible example 来简化测试可能的解决方案,这将有所帮助。您使用闪亮的事实并不是那么相关。假设input$ 中的所有内容都可能是一个字符串。
  • 我不确定你在问什么,但如果你使用"\u03BCg/m\u00B3" 作为μg/m³ 部分,它会很好地打印出来。
  • 已将我的代码添加到原始问题中
  • 你这个小美女@AllanCameron。这很有效:) 谢谢一百万。
  • 很棒的@stixmcvix。已添加为答案。

标签: r ggplot2


【解决方案1】:

我不确定您在问什么,但是如果您将"\u03BCg/m\u00B3" 用于μg/m³ 部分,它会很好地打印出来。

【讨论】:

    【解决方案2】:

    或者如果你想使用正确的绘图表达式,它看起来像这样

    library(ggplot2)
    ggplot(mtcars) + 
      aes(x=mpg, y=disp) +
      labs(title = bquote("Number of times where UK emissions of "~.(input$select)~ 
                         " exceeded"~.(input$number)~mu*g/m^3))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-30
      • 1970-01-01
      • 1970-01-01
      • 2021-10-31
      • 1970-01-01
      • 2016-11-05
      • 1970-01-01
      相关资源
      最近更新 更多