【问题标题】:Having Trouble Making ggplot 3D Using plot_gg使用 plot_gg 制作 ggplot 3D 时遇到问题
【发布时间】:2020-08-01 19:56:58
【问题描述】:

我于 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)

【问题讨论】:

    标签: r ggplot2 maps gis rayshader


    【解决方案1】:

    我认为您可能缺少 sf 包。然后你可以使用 geom_sf 而不是 geom 多边形,例如

    geom_sf(aes(fill = Count)) +

    通过https://www.tylermw.com/3d-ggplots-with-rayshader/查看北卡罗来纳州示例

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

    【讨论】:

      猜你喜欢
      • 2013-05-02
      • 2016-03-12
      • 1970-01-01
      • 2018-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-24
      相关资源
      最近更新 更多