我在 2020 年 3 月在美国各州制作了 COVID 病例的 ggplot,但是当我尝试运行 plot_gg 函数时,它显示为平面图像。我觉得我没有告诉函数高度变量应该是什么(在这种情况下是计数),但是无论我尝试什么,它要么不起作用,要么完全弄乱了地图。
# Libraries
library(leaflet)
library(tidyverse)
library(ggmap)
library(leaflet.extras)
library(htmltools)
library(ggplot2)
library(maps)
library(mapproj)
library(mapdata)
library(rayshader)
library(viridis)
# US States
s <- map_data('state')
ggplot(s, aes(x=long, y=lat, group = group, fill = region)) +
geom_polygon(color='black') +
coord_map('polyconic') +
guides(fill = F)
#COVID DAta -USA
c <- read.csv(file.choose(), header = T)
usa <- c %>% filter(country == 'United States')
usa <- usa %>% group_by(province)%>%
summarise(count=n())%>%
arrange(desc(count))
#Merge Data
usa$province<- tolower(usa$province)
data <- merge(s, usa,
by.x = 'region',
by.y = 'province')
#ggplot
gg_usa = ggplot(data, aes(x=long, y=lat,
group=group,
fill=count)) +
geom_polygon(color='grey') +
coord_map('polyconic') +
scale_fill_gradient2(low='white', high='purple') +
theme_void() +
ggtitle('COVID CASES MARCH 2020')
#Plot3d
plot_gg(gg_usa, multicore = TRUE, width = 6, height = 4)