Code Monkey home page Code Monkey logo

Comments (7)

JohnCoene avatar JohnCoene commented on June 15, 2024 1

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

from echarts4r.

rdatasculptor avatar rdatasculptor commented on June 15, 2024 1

You can define the order of the factor levels using factor()

from echarts4r.

JohnCoene avatar JohnCoene commented on June 15, 2024

Thank you for the detailed post but could you give a minimal reproducible example that does not require download a CSV?

from echarts4r.

MrMisc avatar MrMisc commented on June 15, 2024

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

from echarts4r.

MrMisc avatar MrMisc commented on June 15, 2024

Interesting. The problem now is that the order of the years is not respected.

from echarts4r.

MrMisc avatar MrMisc commented on June 15, 2024

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

from echarts4r.

oobd avatar oobd commented on June 15, 2024

It seems to work fine...
Or is it breaking down when more countries are added?

library(forcats)
library(dplyr)

data <- data %>% arrange(Year) %>% mutate(Year = fct_inorder(as.character(Year), ordered = T))

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

image

from echarts4r.

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.