Hi everyone,
I would like to plot a map from a part of Germany. My code is not plotting the map. It is only plotting the title.
This is the code:
library(highcharter)
# Fetch the map data for Germany
map_data <- "https://code.highcharts.com/mapdata/countries/de/de-all.geo.json"
# Prepare the demo data
data <- data.frame(
id = c('DE-SL', 'DE-BY', 'DE-BW', 'DE-BB', 'DE-MV', 'DE-SN'),
value = c(136, 120, 169, 109, 137, 109)
)
# Create the chart
highchart(type = "map") %>%
hc_title(text = "Highcharts Maps basic demo") %>%
hc_subtitle(text = 'Source map: Germany') %>%
hc_colorAxis(min = 0) %>%
hc_mapNavigation(enabled = TRUE) %>%
hc_add_series(data = data, mapData = map_data, joinBy = "hc-key", name = "Random data",
value = "value", dataLabels = list(enabled = TRUE, format = "{point.name}")) %>%
hc_plotOptions(
map = list(
states = list(
hover = list(
color = "#BADA55"
)
)
)
)
or another code that i tried is:
library(plotly)
library(jsonlite)
# Fetch the map data
topology <- jsonlite::fromJSON('https://code.highcharts.com/mapdata/countries/de/de-sl-all.topo.json')
# Prepare the demo data
data <- data.frame(
id = c('de-sl-10042000', 'de-sl-10043000', 'de-sl-10044000', 'de-sl-10041000', 'de-sl-10045000', 'de-sl-10046000'),
value = c(136, 120, 169, 109, 137, 109)
)
# Create a plotly choropleth map
plot_ly(
type = "choropleth",
locationmode = "ISO-3",
locations = data$id,
z = data$value,
colorscale = "Viridis",
text = data$id,
hoverinfo = "text",
marker = list(line = list(color = "rgb(255,255,255)", width = 1))
) %>%
add_trace(
type = "choropleth",
locations = data$id,
z = data$value,
text = data$id,
hoverinfo = "text",
showscale = FALSE
) %>%
layout(
title = "Plotly Choropleth Map",
geo = list(scope = "world", resolution = 50, showframe = FALSE, showcoastlines = FALSE)
)
Any idea where the problem could be?
Thanks in advance