【问题标题】:Adding title to streamgraph in R (github package)在 R 中为流图添加标题(github 包)
【发布时间】:2019-09-12 20:24:17
【问题描述】:

我有这样的“子示例”数据

structure(list(monthyr = structure(c(17287, 17287, 17287, 17287, 
17287, 17287, 17287, 17287, 17287, 17287, 17287, 17287, 17287, 
17287, 17287, 17287, 17287, 17287), class = "Date"), Location = c("TAI", 
"NAM", "LUI", "HEE", "BRA", "KEI", "TAI", "NAM", "LUI", "HEE", 
"BRA", "KEI", "TAI", "NAM", "LUI", "HEE", "BRA", "KEI"), ID = structure(c(-719050, 
-718685, -718320, -717954, -717589, -717224, -719050, -718685, 
-718320, -717954, -717589, -717224, -719050, -718685, -718320, 
-717954, -717589, -717224), class = "Date"), Type = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 
3L), .Label = c("Industrial.compound", "Pesticide", "Pharmaceutical"
), class = "factor"), value = c(0.885230769230769, 1.9203125, 
3.26635, 0.950052631578947, 2.87133333333333, 3.194775, 0.0823076923076923, 
0.190833333333333, 0.467142857142857, 0.58173125, 0.1375, 0.3777475, 
0.0215555555555556, 0.240236363636364, 0.340790909090909, 0.150083333333333, 
0.103333333333333, 0.2665)), row.names = c(29L, 65L, 107L, 149L, 
194L, 237L, 279L, 315L, 357L, 399L, 444L, 487L, 529L, 565L, 607L, 
649L, 694L, 737L), class = "data.frame")
> 

我想使用来自https://github.com/hrbrmstr/streamgraphstreamgraph

所以我这样做了:

sg<-streamgraph(subexample,"Type","value", "ID" )%>%
  sg_legend(show=TRUE, label="Parameter: ")%>%
  sg_axis_x(1, "ID")%>% sg_axis_y(0)

我得到了一个不错的流图,但是当我添加 sg_title

sg<-streamgraph(subexample,"Type","value", "ID" )%>%
      sg_legend(show=TRUE, label="Parameter: ")%>%
      sg_axis_x(1, "ID")%>% sg_axis_y(0)%>%sg_title("Title example") 

我在控制台中得到一个巨大的代码,而不是带有标题的流图。

我试着像这样分开它:

sg<-streamgraph(subexample,"Type","value", "ID" )%>%
  sg_legend(show=TRUE, label="Parameter: ")%>%
  sg_axis_x(1, "ID")%>% sg_axis_y(0)

sg_title(sg, "Title example")

但没有结果。

你知道我需要做什么才能获得带有标题的流图吗?

【问题讨论】:

    标签: r github htmlwidgets stream-graph


    【解决方案1】:

    我找到了这个解决方案。

    library(streamgraph)
    library(dplyr)
    library(shiny)
    
    ui = shinyUI(fluidPage(
      h3("Title Example", style="text-align:center"),
      streamgraphOutput('sg1')
    ))
    
    server = function(input, output) {
    
      sgexample<-streamgraph(subexample, "Type","value", "ID" )%>%
        sg_legend(show=TRUE, label="Parameter: ")%>%
        sg_axis_x(1, "ID")%>% sg_axis_y(0)
    
      output$sg1 <- renderStreamgraph(sgexample)
    
    }
    
    shinyApp(ui = ui, server = server)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-17
      • 1970-01-01
      • 1970-01-01
      • 2018-08-10
      • 2013-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多