R 使用闪亮的输入、文本和希腊字母为ggplot添加标题
我想在ggplot中添加以下标题:R 使用闪亮的输入、文本和希腊字母为ggplot添加标题,r,ggplot2,R,Ggplot2,我想在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 selec
"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)
使用了粘贴、表达式和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}"))
我不知道你在问什么,但如果你对
μg/m³
零件使用“\u03BCg/m\u00B3”
,它会很好地打印出来 或者,如果要使用正确的plotmath表达式,它将如下所示
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))
您的
expression
和bquote
的组合到底是什么样子的?如果您提供了某种帮助,使测试可能的解决方案更容易,这将有所帮助。事实上,您使用的是shiny并不是那么重要。假设从输入$
中的所有内容都可能是一个字符串。我不确定你在问什么,但是如果你使用“\u03BCg/m\u00B3”
作为μg/m³
部分,它会打印得很好。我已经在原始问题中添加了我的代码you little beauty@AllanCameron。这真是一种享受:)万分感谢。太棒了@stixmcvix。已添加作为答案。