【发布时间】:2020-04-15 13:24:02
【问题描述】:
我正在尝试使用 plotly 制作交互式 ggplot2 地图。
在下面的代码中,我为每个部门创建了一张不同颜色的法国地图:
library(tidyverse)
library(stringr)
library(stringi)
library(maps)
library(ggplot2)
map <- map_data("france")
map_theme <- theme(title=element_text(),
plot.title=element_text(margin=margin(20,20,20,20), size=18, hjust = 0.5),
axis.text.x=element_blank(),
axis.text.y=element_blank(),
axis.ticks=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
panel.grid.major= element_blank(),
panel.background= element_blank())
p = ggplot(map, aes(long,lat, group = group, fill = region)) +
geom_polygon() +
coord_map() +
theme(legend.position = "none") +
map_theme
plot(p)
ggplotly(p)
plot(p) 和 ggplotly(p) 将给出相似的图形,但 plotly 提供的图形似乎被拉伸了。地图有问题。避免这种情况的最佳策略是什么?
【问题讨论】: