Search code examples
rdata-visualizationstream-graph

Creating a streamgraph in R


I would like to visualize my data frame which contains 5 numeric values that change over time. I would like to visualize it using a streamgraph, but I don't seem to be doing it the right way.

Here is the official site of the R package to make these kinds of graphs, but I am not very familiar with it. I have successfuly installed it and examples work fine, but I can't create the one I need.

I have also created a new data frame, which has every numeric value on separate row to have the "key-value-year" format, but in fact, they "year" column is not a year, but specific time period, for me it is 30 minutes, but it is changing over time, so it should be suitable for this situation.

I have tried something like this:

library(streamgraph)
tcc1_df %>% 
  streamgraph(key = "char", value = "value", year = "HfHr", interactive = TRUE) %>% 
  sg_colors("Reds")

Can you please help me how to do that? Or can you suggest me any other way to visualize these kind of data (in R)?

Thanks in advance.

Example of the data frame:

    min    avgvar_diff    avg     avgvar_sum   max
1  0.066  0.253732018  0.5538182  0.8539043   1.757
2  0.066  0.263114709  0.4832727  0.7034307   1.646
3  0.066  0.230794382  0.4575455  0.6842965   1.607
4  0.067  0.211000618  0.4048182  0.5986357   1.618

Example of the new data frame (tcc1_df):

        char      value     HfHr
1       min     0.0660000    1
2  avgvar_diff  0.2537320    1
3       avg     0.5538182    1
4   avgvar_sum  0.8539043    1
5       max     1.7570000    1
6       min     0.0660000    2
7  avgvar_diff  0.2631147    2
8       avg     0.4832727    2
9   avgvar_sum  0.7034307    2
10      max     1.6460000    2

Solution

  • You need to use date instead of year in the call to streamgraph. And you also need to define the scale as "continuous" because the default is "date".

    So call should look something like:

    tcc1_df %>% 
    streamgraph(key = "char", value = "value", date = "HfHr", 
                scale = "continuous", interactive = TRUE) %>% 
    sg_colors("Reds")