R 使用plot_gg制作ggplot 3D时遇到问题

R 使用plot_gg制作ggplot 3D时遇到问题,r,ggplot2,maps,gis,rayshader,R,Ggplot2,Maps,Gis,Rayshader,我在2020年3月绘制了美国各州的新冠病毒病例的gg图,但当我尝试运行plot_gg函数时,它显示为平面图像。我觉得我并没有告诉函数高度变量应该是什么(在本例中为count),但无论我尝试什么,它要么不起作用,要么完全弄乱了地图 # Libraries library(leaflet) library(tidyverse) library(ggmap) library(leaflet.extras) library(htmltools) library(ggplot2) library(maps

我在2020年3月绘制了美国各州的新冠病毒病例的gg图,但当我尝试运行plot_gg函数时,它显示为平面图像。我觉得我并没有告诉函数高度变量应该是什么(在本例中为count),但无论我尝试什么,它要么不起作用,要么完全弄乱了地图

# 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)
#库
图书馆(单张)
图书馆(tidyverse)
图书馆(ggmap)
图书馆(单张、附加资料)
图书馆(htmltools)
图书馆(GG2)
图书馆(地图)
图书馆(mapproj)
图书馆(地图数据)
库(光线着色器)
图书馆(绿色)
#美国各州
s%
排列(描述(计数))
#合并数据

美国$省我想你可能错过了sf套餐。然后您可以使用geom_sf而不是geom多边形,例如

geom_sf(aes(填充=计数))+

查看北卡罗莱纳州的例子

如果你使用几何多边形,那么我认为你需要在plot_gg中添加一个scale参数