JohnCoene / echarts4r

🐳 ECharts 5 for R
http://echarts4r.john-coene.com/
Other
585 stars 82 forks source link

e_flip_coords doesn't flip correctly if x-axis is non-categorical #578

Open sactyr opened 8 months ago

sactyr commented 8 months ago

I understand x_axis should always be categorical but perhaps we could put in class check i.e. is.character or is.factor in e_flip_coords to force an error, instead of silently generating an incorrect chart? Thank you for this great package!

With non-categorical x-axis

df <- data.frame(
  x = 1:12 # e.g. typically for months in integer
  ,y = runif(12)
)

df %>%
  e_charts(x) %>%
  e_bar(y) %>% 
  e_flip_coords()

image

With x-axis turned into factor

df <- data.frame(
  x = as.factor(1:12)
  ,y = runif(12)
)

df %>%
  e_charts(x) %>%
  e_bar(y) %>% 
  e_flip_coords()

image

munoztd0 commented 6 months ago

mhhh this is much more complex that I thought because it has to work for different types of graphs, with x and y as integers, etc..

JohnCoene commented 6 months ago

I should not have created coord_flip

With echarts.js you should just be able to

df <- data.frame(
  x = 1:12 # e.g. typically for months in integer
  ,y = runif(12)
)

df %>%
  e_charts(y) %>%
  e_bar(x)