在R(github包)中向streamgraph添加标题

问题描述 投票:0回答:1

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

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")
> 

我想使用streamgraphhttps://github.com/hrbrmstr/streamgraph

所以我这样做了:

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个回答
0
投票

我找到了这个解决方案

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)
© www.soinside.com 2019 - 2024. All rights reserved.