0

I have data like this "subexample"

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

I want to use the streamgraph package from https://github.com/hrbrmstr/streamgraph

So I did this:

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

I got a nice streamgraph but when I add the 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") 

I get a huge code in the console and not the streamgraph with the title.

I tried separating it like this:

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

But no results.

What I need to do to get the streamgraph with the title?

Braiam
  • 1
  • 11
  • 47
  • 78
user195366
  • 465
  • 2
  • 13

1 Answers1

1

I found this solution.

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)
user195366
  • 465
  • 2
  • 13