JohnCoene / echarts4r

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

e_datazoom: largest data point omitted at seemingly random zoom starting values (v0.4.4) #506

Closed awcm0n closed 1 year ago

awcm0n commented 1 year ago

It depends on the zoom starting value whether the data point with the largest x value is shown. The figure contains an illustration based on the following code:

library(echarts4r)
library(tidyverse)

df <- tibble(x = c(1, 2, 3, 4, 5),
             y = c(1, 2, 3, 4, 5),
             z = c(1, 2, 3, 4, 10))

df |> 
  e_charts(x) |>
  e_scatter(y, size = z) |>
  e_datazoom()
e_datazoom
rdatasculptor commented 1 year ago

I see what you mean. I guess it is a problem caused by something at the js side, not the R side.

At least you can use a trick by picking a higher x axis maximum (e.g. 5%). This way the problem is not eminent anymore:

df |> 
  e_charts(x) |>
  e_scatter(y, size = z) |>
  e_datazoom() %>%
  e_x_axis(max = max(df$x) + (0.05 * max(df$x)))

Or you can set max = 6 in this particular case to make the x axis a little less specific.

Maybe not the cleanest solution, but does this help you?