-
-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stacked bar plot & e_connect with e_river #597
Comments
Thank you for the detailed post but could you give a minimal reproducible example that does not require download a CSV? |
Sure. I think this example might work equivalently for now data<-data.frame(
Country = rep(c("Afghanistan", "Albania", "Angola", "Argentina"), each = 5),
Year = rep(c(2010, 2019, 2017, 2009, 2014), 4),
n = sample(1:100, 20, replace = TRUE),
Deaths = sample(1:1500, 20, replace = TRUE),
Cases = sample(1:2000, 20, replace = TRUE),
lethality = runif(20, min = 0, max = 1),
database_name.x = rep(c("Islamic Republic of Afghanistan", "Republic of Albania", "Republic of Angola", "Argentine Republic"), each = 5),
lat.x = rep(c(33.00, 41.00, -12.50, -34.00), each = 5)
) |
Year is numeric here so it's going to be treated as such and start from 0 data |> dplyr::mutate(Year = as.factor(Year)) |> group_by(Country) |> e_chart(Year) |> e_bar(n, stack = "group") |
Interesting. The problem now is that the order of the years is not respected. |
You can define the order of the factor levels using |
Why wouldn't something like say, data|>group_by(Country)|>e_charts(Year)|>
e_bar(n, stack = "group")|>
e_legend(right = 5,top = 80,selector = "inverse",emphasis = list(selectorLabel = list(offset = list(10,0)), focus = "series"),show=TRUE,icon = 'circle',emphasis = list(selectorLabel = list(offset = list(10,0))), align = 'right',type = "scroll",width = 10,orient = "vertical")|>
e_x_axis(min = min(data$Year)-1,max = max(data$Year)+1)|>
e_tooltip() Not work? It looks like it almost would, however, the stack isn't perfect. Many countries disappear behind others in this configuration for some reason |
It seems to work fine... library(forcats) data <- data %>% arrange(Year) %>% mutate(Year = fct_inorder(as.character(Year), ordered = T)) data|>group_by(Country)|>e_charts(Year)|> |
I have another question regarding creating stacked barplots. These always seem a little difficult to do. Consider the following,
DirectExample.csv
For my case, the plot ends up with a very large range for Year which I do not know the cause of. Additonally, I want this plot to be a stacked barplot where the x-axis would be Year and the y-axis would be count. I was hoping for the colours of each of the countries be represented as distinct "stacks" per Year represented by a bar.
I haven't been having much luck looking online for this type of stuff.
I am wondering if anyone has a solution to this such that I can also link it appropriately with a current working river plot that is as follows
I was hoping to use e_connect or e_brush to pair the 2 charts together nicely.
However, when I try to do something like that, I just get a blank screen like for the following attempt.
Clearly I am using it wrongly, but I haven't quite figured out what the cause might be.
Thank you for your time!
The text was updated successfully, but these errors were encountered: