Open MrMisc opened 7 months ago
The thing with e_river
is that you need real dates instead of integers. It could be group_by works, not sure, but I followed this example with your data:
library(dplyr)
library(tidyr)
filled_data2 <- filled_data %>%
select(groups, dates, values) %>%
pivot_wider(names_from = "groups", values_from = "values") %>%
mutate(dates = seq.Date(Sys.Date() - 30, Sys.Date(), by = "day")[1:n()])
filled_data2 |>#group_by(groups)|>
e_charts(dates) |>
e_river(`Egg -> Faeces`) |>
e_river(`Faeces -> Host`) |>
e_river(`Faeces -> Host[*]`) |>
e_river(`Faeces <-> Faeces`) |>
e_river(`Host -> Egg`) |>
e_river(`Host <-> Host`) |>
e_river(`Host 0[*]` ) |>
e_river(marker) |>
e_tooltip() |>
e_theme("westeros")
Regarding the other issues (usually it is better to address one problem or question per issue, instead of three... :)), I am not entirely sure what your emphasis question is. For the other question, the one about connecting charts: I think it is better to make an example with two working charts first. Then we can take a look at how to connect them. Thanks!
@rdatasculptor Ah, that would be better then yeah? Gotcha. I will give the connecting thing a go again and be sure to open a separate issue for that. Thank you for the clarification and the help! I appreciate it!
For some reason, the following does not work. Assuming that I have followed your example here correctly,
filled_data|>mutate(dates = seq.Date(Sys.Date() - 30, Sys.Date(), by = "day")[1:n()])|>group_by(groups)|>e_charts(dates)|>
e_river(values)
Yet, I get the same sort of issue where the river plot simply does not show. I can see some labels, but no actual streams of data.
The thing is I removed the whole group_by thing. Instead I made an e_river of each of your group variable.
What happens if you copy my exact code and run it?
It works perfectly when that is done. But I was wondering why that wouldn't work if the x-axis has already been readjusted to be dates?
Funnily I just realised, the dates thing should ideally be in hours since the time here is in hours XD
What happens if you put it in this order:
filled_data|>group_by(groups)|>mutate(dates = seq.Date(Sys.Date() - 30, Sys.Date(), by = "day")[1:n()])|>e_charts(dates)|> e_river(values)
Can we have a small MRE for this?
Can we have a small MRE for this?
At the moment when I make MREs for this, the e_river issue cannot be replicated. I do not understand why that is the case. For example, if I make a faux dataset like so
df_eg <- data.frame(
Year = rep(1980:2021, each = 6),
Divorce_Amt = sample(800:2300, 252, replace = TRUE),
Category = rep(c(" Under 5 Years (Number)", " 5-9 Years (Number)", " 10-14 Years (Number)", " 15-19 Years (Number)", " 20-24 Years (Number)", " 25-29 Years (Number)", " 30 Years & Over (Number)"), times = 36)
)
df_eg %>% mutate(Year = as.Date(paste0(df_eg$Year, "-01-01"))) |> group_by(Category) |>
e_charts(Year) |>
e_river(Divorce_Amt)|>
e_tooltip(emphasis = list(focus = "self"))|>
e_legend(right = 5,top = 30,selector = "inverse",show=TRUE,icon = 'circle',emphasis = list(selectorLabel = list(offset = list(10,0)),focus = "series"),type = "scroll",width = 900,orient = "horizontal")|>
e_title("Distribution of duration of anulled marriages over time","5 year resolutions")
No problem. However, if I use the actual dataset based off of this dataset
df<-read.csv("dataset.csv")
df %>% mutate(Year = as.Date(paste0(df$Year, "-01-01"))) |> group_by(Category) |>
e_charts(Year) |>
e_river(Divorce_Amt)|>
e_tooltip(emphasis = list(focus = "self"))|>
e_legend(right = 5,top = 30,selector = "inverse",show=TRUE,icon = 'circle',emphasis = list(selectorLabel = list(offset = list(10,0)),focus = "series"),type = "scroll",width = 900,orient = "horizontal")|>
e_title("Distribution of duration of anulled marriages over time","5 year resolutions")
river just breaks, like the initial example I showed. Sorry, I have tried but I do not know what distinguishes the dataset I am providing versus the faux dataset I fabricated that makes river work somehow.
Same here, repeated measures problem I guess.
library(echarts4r)
library(tidyverse)
df<-read.csv("dataset.csv")
df_unique <- df |>
mutate(Year = as.Date(paste0(df$Year, "-01-01"))) |>
group_by(Category, Year) |>
summarise(Divorce_Amt = mean(Divorce_Amt)) |>
ungroup()
plot <- df_unique |>
group_by(Category) |>
e_charts(Year) |>
e_river(Divorce_Amt)|>
e_tooltip(emphasis = list(focus = "self"))|>
e_legend(right = 5,top = 30,selector = "inverse",show=TRUE,icon = 'circle',emphasis = list(selectorLabel = list(offset = list(10,0)),focus = "series"),type = "scroll",width = 900,orient = "horizontal")|>
e_title("Distribution of duration of anulled marriages over time","5 year resolutions")
is that better ?
In hopes of keeping the dataset to the same set of issues, I tried to make this into 1 post - I hope that is okay.
The illustrating example I have is as follows for filled_data.csv as the dataset.
I essentially have 3 issues I would really appreciate some help on:
How do I change the emphasis effect in say an e_area curve to for instance, have more blur, make the other sets have even less opacity, or move the series in question more (if possible)? I am getting the impression that echarts has those features from here even though I acknowledge this is for the series-bar. Is there something similar for something like e_area?
In my running example, for whatever reason the e_river plot does not appear to work. Is there a reason for that? I initially reasoned that it was probably due to the volume of the dataset, but after trying it recently for other datasets, I do not quite understand what might be causing it now.
I haven't had much success with this in other examples, and since the river plot doesn't even work here, I haven't considered trying it here, but is anyone here able to perhaps show me an instance of using e_connect as described here? I vaguely recall a slightly different example existing here, but it showed a really nice example of 2 linked charts. I would like to see if it is possible to do so with the 2 plots I am aspiring to build here (1 done, the 2nd stream one being my running issue)?
Thank you for your time!