【发布时间】:2021-11-13 09:53:41
【问题描述】:
我有一个包含捷克共和国 14 个地区的经纬度信息的电子表格(文件 here)。我正在尝试绘制地图并为每个区域的活动案例放置气泡。经纬度坐标适用于每个地区的首府城市。
library(sf)
library(ggplot2)
library(maps)
library(rstudioapi)
library(dplyr)
library(ggmap)
library(mapproj)
library(viridis)
#----------------------------#
# Set your working directory #
#----------------------------#
setwd(dirname(rstudioapi::getActiveDocumentContext()$path)) # RStudio IDE preferred
getwd() # Path to your working directory
# Country Boundary and the 14 regions within the Czech Republic
worldmap <- map_data("world")
worldmap2 <- dplyr::filter(worldmap, region %in% data.frame(countries = "Czech Republic"))
ggplot(worldmap2) + geom_polygon(aes(long,lat, group=group), col = "black", fill = "white", size = 1) +
labs(title = "COVID-19 in the Czech Republic", subtitle = "As of July 1, 2021", x = "Longitude", y = "Latitude",
caption = "(Source: Ministerstvo zdravotnictví České republiky)")
电子表格的第六列包含活动案例编号。我试图让数字在上面的地图上显示为气泡。我尝试了以下方法,但所有点的大小都相同。如何合并情节 1 和情节 2?
my_df <- read.csv("CZE_InitialSeedData.csv", header = T)
class(my_df)
my_sf <- st_as_sf(my_df, coords = c('Lon', 'Lat'))
my_sf <- st_set_crs(my_sf, value = 4326)
my_sf
seedPlot <- ggplot(my_sf) +
geom_sf(aes(fill = InitialInfections))
seedPlot <- seedPlot +
scale_fill_continuous(name = "Active Cases", low = "pink", high = "red", na.value = "grey50")
seedPlot <- seedPlot +
theme(legend.position = "bottom", legend.text.align = 1, legend.title.align = 0.5)
seedPlot
【问题讨论】:
标签: r dictionary ggplot2 geospatial bubble-chart