1

I'm trying to create a map of New Zealand in R using the library echarts4r but the map looks tiny and I couldn't figure out how to zoom in or determine lat/long boundaries to make it more visible. Here is my code (adapted from the example in the documentation https://echarts4r.john-coene.com/articles/map.html)

library(echarts4r.maps)

df <- data.frame(
  region = c("Wellington", "Auckland"), 
  value = c(10,20)
)

df |> 
  e_charts(region) |>
  em_map("New_Zealand") |> 
  e_map(value, map = "New_Zealand") |> 
  e_visual_map(value) |> 
  e_theme("infographic")

screenshot
enter image description here

Do you know how to zoom in maps, or set lat/long boundaries, in echarts4r? Any help would be much appreciated!

Quinten
  • 35,235
  • 5
  • 20
  • 53

2 Answers2

0

I think there may be something wrong with the encoding of the map coming from echarts4r.maps, but I'm not sure.

I can tell you that Wellington is not listed as a city in New Zealand in the data behind echarts4r. I thought that might have been why, but it had nothing to do with the rendering/zoom issue.

I looked up the lat/long boundaries of NZ and used that in the plot, and it's definitely readable now.

df <- data.frame(
  region = c("Southland", "Auckland"), 
  value = c(1, 2)
)

df |> 
  e_charts(region, elementId = 'chart') |>
  em_map("New_Zealand") |> 
  e_map(value, map = "New_Zealand",
        boundingCoords = list(
          list(166.4669, -48.0624), list(179.0637, -34.1473)
        )) |> 
  e_visual_map(value) |> 
  e_theme("infographic")

enter image description here

Kat
  • 15,669
  • 3
  • 18
  • 51
0

Bless you Kat, really was struggling to Code to get it in shiny add this to a shiny app to use it as a filter for a bar chart.

using https://psim.shinyapps.io/echarts4r_callbacks/ to get the filtering from the mouse click.

# Update the filter date on click on data point
observeEvent(input$chart_clicked_data, {
filter_date(input$chart_clicked_data$value[1])
})

how easy is that.