Comments (8)
Learning from an "exercise" is fun, but translating from another library is less so.
Your questions are interesting, please make an effort to code in echarty next time.
Here we go:
raw <- read.csv("DirectExample.csv")
df <- raw |> select(Year,n,Country) |> arrange(Year) |>
mutate(Year=factor(Year, ordered=T))
legend <- list(type= "scroll",orient= "vertical", pageButtonPosition= 'start',
right= 5,top = 30, icon = 'circle', align= 'right', height='85%')
priver <- ec.init(preset= F,
series= list(list(type= 'themeRiver',
data= ec.data(df), label= list(show=F))),
singleAxis= list(min='dataMin', max= 'dataMax',
axisLabel= list(formatter= htmlwidgets::JS("(x) => x.toString()"))),
dataZoom= list(type= "slider", bottom= 10),
legend= legend,
tooltip= list(trigger = "axis"),
title= list(text="ALL Anthrax Incident Reports by Year",
subtext="WAHIS Public Quantitative data from WHO")
)
pbar <- df |> group_by(Country) |>
ec.init(
series.param= list(type='bar', stack= "grp", encode= list(x='Year',y='n')),
legend= legend,
tooltip= list(show=T)
)
ec.util(cmd= 'tabset', River=priver, Bar=pbar)
# ec.util(cmd='layout', list(priver,pbar), cols=2)
About connecting the charts - please notice that they do not share the same data (bar is grouped, river is not). So I doubt connect is possible.
from echarty.
Regarding this dataset, could I get some insight into why the legend for the following does not quite work?
#Bar plot
raw<-read.csv("DirectExample.csv")
legend <- list(show = T,type= "scroll",orient= "vertical", pageButtonPosition= 'start',
right= 5,top = 30, icon = 'circle', align= 'right', height='85%')
raw %>% mutate(Year = as.Date(paste0(raw$Year, "-01-01"))) |> group_by(Country) |>
ec.init(
series.param = list(type ='bar',stack = "grp",encode = list(x = 'Year',y = 'n')),
tooltip = list(show = T),
legend = legend,
)
The legned does not get sorted to the right and some of the bars appear to be floating from the output?
from echarty.
The legend does not get sorted to the right
I see it sorted to the right...
some of the bars appear to be floating from the output
yes, because Year has been changed from type factor(value) to type time. Bars can be stacked only on a value xAxis. See docs.
from echarty.
Legend appears to still remain fully covering the entire screen on my side. Unfortunate that the example isn't reproducing so on yours.
Could you clarify for me what you mean by "factor(value)"? The Year column is originally in integer format and I can only conceive of maybe changing it to numeric (using as.numeric) if not just using integer to plot. However, the result destroys the individual stacked effect. For example
raw %>% mutate(Year = as.numeric(raw$Year)) |> group_by(Country) |>
ec.init(
series.param = list(type ='bar',stack = "grp",encode = list(x = 'Year',y = 'n')),
xAxis = list(max = 2030,min = 2004),
tooltip = list(show = T),
legend = legend,
)
As of right now even trying to remove the legend does not seem to be working on my side either.
raw %>% mutate(Year = as.numeric(raw$Year)) |> group_by(Country) |>
ec.init(
series.param = list(type ='bar',stack = "grp",encode = list(x = 'Year',y = 'n')),
xAxis = list(max = 2030,min = 2004),
tooltip = list(show = T),
legend = list(show=FALSE),
)
from echarty.
Sorry about "factor(value)", should be "factor(category)". You can use as.factor or as.character to create a category column.
legend <- list(show = T,type= "scroll",orient= "vertical", pageButtonPosition= 'start',
right= 5,top = 30, icon = 'circle', align= 'right', height='85%')
raw %>% mutate(Year = as.character(raw$Year)) |> group_by(Country) |>
ec.init(
series.param = list(type ='bar',stack = "grp",encode = list(x = 'Year',y = 'n')),
tooltip = list(show = T),
legend = legend,
)
However, since Year is not sorted as in my original example, now the X axis is not in order.
from echarty.
Hmmm. A bit of a strange question, but given that, do you have a suggested mode to depict this data since it looks like barcharts are just fundamentally not suited for time series data like this?
I have been exploring alternatives like scatter plots for this type of data with the same underlying logic (pretty much identical), but scatter plots don't visually work very well, so I am a little stumped. I generally work with data in this scenario quite often.
from echarty.
The problem is probably not the chart type, but the sheer amount of data you are trying to present at once.
data |> group_by(Year) |> summarize(cc=sum(n())) |> summarize(tot=sum(cc))
gives a total of 984 stacked bars. That is way to large for users to grasp. Maybe a "divide and rule" strategy will help, like "top 10 vs bottom 10", drill-down interactive maps or other categorizations.
BTW stacked bars are very compact and suitable for size comparison, i.e. a good type choice.
from echarty.
I noticed that the bar chart doesn't break if I do make the set a little smaller (for instance, only plot from 2008 onwards instead of 2005).
Thank you for your help so far. Has been very useful.
from echarty.
Related Issues (20)
- charts morphing HOT 1
- Combinations of echarts4r and charty HOT 5
- replicate ECharts examples - polar HOT 1
- Method for initializing echart with highlighted series applied? HOT 2
- 1.5.0 causes breaks for all data without rownames or non-numeric keys HOT 3
- Mute visualMap color on specific series elements HOT 7
- Each line a different color using `dataset` option HOT 2
- Error: No handler registered mouseover since v1.5.4 HOT 3
- No handler for mouseover HOT 2
- Compressing sparse bars
- 3d scatterplot animations HOT 1
- Separate symbols/custom shapes | Within timeline frames HOT 1
- Regarding geo plots HOT 5
- Legend issue HOT 3
- Features question HOT 10
- Understanding formatter HOT 3
- Combining pie chart with bar chart HOT 17
- Is GL screenshot possible HOT 7
- Possible features: Including more information HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from echarty.