【发布时间】:2019-01-29 11:17:09
【问题描述】:
我正在使用 R 中的 highcharter 包绘制一个 highcharts 地图。我已经添加了一些点(城市),并希望通过使用世界地图坐标绘制一条附加直线来链接它们。
我已经设法绘制直线,首先绘制地图,然后将鼠标悬停在显示绘图坐标的城市上,然后使用上述绘图坐标重新绘制绘图。 (注意:我使用了 PLOT 坐标,而我的目标是直接使用 WORLD MAP 坐标。) 如果你只有一两个城市,那没什么大不了的。但是如果你有 100 个城市/点,那就很烦人了。我想答案会是这样的:Is it possible to include maplines in highcharter maps?。
谢谢!
这是我的代码:
library(highcharter)
library(tidyverse)
# cities with world coordinates
ca_cities <- data.frame(
name = c("San Diego", "Los Angeles", "San Francisco"),
lat = c(32.715736, 34.052235, 37.773972), # world-map-coordinates
lon = c(-117.161087, -118.243683, -122.431297) # world-map-coordinates
)
# path which I create AFTER the first drawing of the map as I get the
# plot-coordinates when I hover over the cities.
path <- "M669.63,-4963.70,4577.18,-709.5,5664.42,791.88"
# The goal: the path variable above should be defined using the WORLD-
# coordinates in ca_cities and not using the PLOT-coordinates.
# information for drawing the beeline
ca_lines <- data.frame(
name = "line",
path = path,
lineWidth = 2
)
# construct the map
map <- hcmap("countries/us/us-ca-all", showInLegend = FALSE) %>%
hc_add_series(data = ca_cities, type = "mappoint", name = "Cities") %>%
hc_add_series(data = ca_lines, type = "mapline", name = "Beeline", color = "blue")
map
【问题讨论】:
标签: r r-highcharter