【问题标题】:How to put a superscript and special characters in dygraphs axis labels如何在 dygraphs 轴标签中放置上标和特殊字符
【发布时间】:2016-11-29 22:44:37
【问题描述】:

我有一个闪亮的应用程序,它使用 dygraphs 包制作情节。我需要在绘图的轴标签中使用上标和特殊字符。我已经尝试过expression()bquote(),但似乎 dygraphs 无法评估这些功能,因为标签打印为 [Object Object]。

这是一个最小的例子。我需要在 y 标签中上标 87 和 86,并在 x 标签中使用 mu 字符。

library(shiny)
library(dygraphs)

ui <- fluidPage(dygraphOutput("dygraph"))

server <- shinyServer(function(input, output, session) {

  sampleplot <- function(){
    norm <- rnorm(1000,mean=50,sd=7)
    dist <- seq(1,1000,by=1)
    dat <- as.data.frame(cbind(dist,norm))
    names(dat) <- c("Distance","Normal")
    dygraph(dat, ylab="87Sr/86Sr",xlab="Distance (um)") %>% 
      dySeries("Normal",drawPoints = TRUE, pointSize = 2, strokeWidth = 0.0)}

  output$dygraph <- renderDygraph({sampleplot()})


    }
  )


shinyApp(ui=ui,server=server)

【问题讨论】:

    标签: r shiny axis-labels dygraphs


    【解决方案1】:

    我阅读了 JS 的 dygraphs 选项网页,发现轴标签可以采用 HTML,而不仅仅是文本。我查找了如何在 HTML 中输入上标 http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_sup 和特殊字符 http://www.htmlhelp.com/reference/html40/entities/symbols.html 并且成功了!

    library(shiny)
    library(dygraphs)
    
    ui <- fluidPage(dygraphOutput("dygraph"))
    
    server <- shinyServer(function(input, output, session) {
    
      sampleplot <- function(){
        norm <- rnorm(1000,mean=50,sd=7)
        dist <- seq(1,1000,by=1)
        dat <- as.data.frame(cbind(dist,norm))
        names(dat) <- c("Distance","Normal")
        dygraph(dat, ylab="<sup>87</sup>Sr/<sup>86</sup>Sr",xlab="Distance (&mu;m)") %>% 
          dySeries("Normal",drawPoints = TRUE, pointSize = 2, strokeWidth = 0.0)}
    
      output$dygraph <- renderDygraph({sampleplot()})
    
    
        }
      )
    
    
    shinyApp(ui=ui,server=server)
    

    【讨论】:

      猜你喜欢
      • 2013-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多