Giter Site home page Giter Site logo

Comments (8)

helgasoft avatar helgasoft commented on May 18, 2024

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)

image

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.

MrMisc avatar MrMisc commented on May 18, 2024

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.

helgasoft avatar helgasoft commented on May 18, 2024

The legend does not get sorted to the right

I see it sorted to the right...
image

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.

MrMisc avatar MrMisc commented on May 18, 2024

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.

helgasoft avatar helgasoft commented on May 18, 2024

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

image

However, since Year is not sorted as in my original example, now the X axis is not in order.

from echarty.

MrMisc avatar MrMisc commented on May 18, 2024

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.

helgasoft avatar helgasoft commented on May 18, 2024

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.

MrMisc avatar MrMisc commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.