经过进一步调查,并在维护包的人@jbkunst 的帖子和回答之后,有一个修复需要拉取最新版本的包。
这是代码:
remotes::install_github("jbkunst/highcharter")
更多信息可在此链接获得:
https://github.com/jbkunst/highcharter/issues/741
编辑:
这已不再正确,当您从 jbkunst 的 github 存储库下载包的更新版本时,该包也适用于 flexdashboard。
但是,请注意,对于我的具体问题,它嵌入在 flexdashboard 的制作中,拉取最新版本的软件包似乎会引入错误,即第一个图正确显示,而以下图则没有.此错误不一致,因此它可能会或可能不会发生在您的身上。我在 github 页面上为该包添加了一个帖子,如果您有兴趣,请提供一个功能示例:
编辑:
此问题已解决
https://github.com/jbkunst/highcharter/issues/744
为了针对我的具体情况解决这个问题,我提取了最新版本的软件包,然后将地图数据保存为我需要的所有地图的 excel 文件。然后,我依靠确实有效的 JSON 版本来生成地图:
这是一个瓷砖示例:
library(highcharter)
library(tidyverse)
library(jsonlite)
library(httr)
library(readxl)
de_map_js <- read_excel("your path/map.xlsx") # Opening JS Map from Excel
map_data <- as_tibble(data.frame(name = de_map_js$name,
values = sample(c(50:200), 16, replace = T))) # Creating Fake Data by Region for Germany
de_map <- "https://code.highcharts.com/mapdata/countries/de/de-all.geo.json" %>% #Downloading the German Map as JSON
GET() %>%
content()
highchart(type = "map") %>%
hc_title(text = "Title") %>%
hc_subtitle(text = "Subtitle") %>%
hc_add_series_map(map = de_map, df = map_data, joinBy = "name", value = "values", # map = JSON map ; df = data.frame with correct region names ; values = your data values
dataLabels = list(enabled = TRUE
,format = "{point.properties.hc-a2}") # Adding region initials on map
) %>%
hc_colorAxis(stops = color_stops(colors = viridisLite::rocket(213, direction = -1,
begin = 0.2,
end = 1))) %>%
hc_mapNavigation(enabled = TRUE)
这是一个城市泡沫的例子:
library(highcharter)
library(tidyverse)
library(jsonlite)
library(httr)
library(readxl)
df_fake <- data.frame(
name = c("Cologne"),
lat = c(50.9375),
lon = c(6.9603),
z = c(1)
) # Creating fake tile data
df <- data.frame(
name = c("Berlin", "Frankfurt", "Munich", "Cologne"),
lat = c(52.5200, 50.1109, 48.1351, 50.9375),
lon = c(13.4050, 8.6821, 11.5820, 6.9603),
z = c(1000, 500, 750, 1250)
) # Creating bubble map series
de_map_json <- "https://code.highcharts.com/mapdata/countries/de/de-all.geo.json" %>% #Downloading the German Map as JSON
GET() %>%
content()
highchart(type = "map") %>%
hc_add_series_map(map = de_map_json, df = df_fake, joinBy = "name", value = "z") %>% # The fake data goes into the map generation, with the real map as JSON
hc_add_series(
data = df, # Here you can add your data
type = "mapbubble", # The type of plot
name = "city",
minSize = "1%",
maxSize = "5%",
tooltip = list(
pointFormat = "{point.name}: {point.z:,.0f}" # Hover options
)) %>%
hc_mapNavigation(enabled = TRUE) %>%
hc_colorAxis(stops = color_stops(colors = viridisLite::turbo(10, begin = 0.4, end = 0.9))) %>%
hc_title(text = "Title")
这一切都是通过将新版本的包中的 JS 地图保存为 excel(见上文),删除并重新安装旧版本的包,最后使用 JSON 数据而不是 JS 生成地图来实现的。
所有地图都可以在这里找到:
https://code.highcharts.com/mapdata/