我有一個電子表格,上面有捷克共和國14個地區的緯度資訊(檔案
電子表格的第六列有活動的案件編號。我試圖讓這些數字在上述地圖上顯示為氣泡。我嘗試了以下方法,但所有的點都是一樣大的。我怎樣才能合并圖1和圖2呢?
my_df <- read.csv("CZE_InitialSeedData. csv", header = T)
class(my_df)
my_sf < - st_as_sf(my_df, coords = c('Lon'/span>, '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"/span>, 低 = "粉紅色"。 高 = "red", na. value = "grey50")。
seedPlot <- seedPlot
主題(legend.position = "bottom", legend.text。 align = 1, legend. title.align = 0.5)
種子圖
uj5u.com熱心網友回復:
沒有必要將你的資料轉換為sf物件。你可以簡單地通過geom_point將你的資料添加到你的地圖上。為了獲得氣泡地圖你的列與活動的情況下的size美學:
library(ggplot2)
library(maps)
library(dplyr)
worldmap <- map_data("world")
worldmap2 <- dplyr:: filter(worldmap, region == "Czech Republic")
base_map <- ggplot(worldmap2)
geom_polygon(aes(long, lat, group = group)。 col = "black", fill = "white"。 尺寸= 1)
labs()
標題 = "捷克共和國的COVID-19"。 副標題 = "截至2021年7月1日"。 x = "經度"。 y = "Latitude",
caption = "(來源:Ministerstvo zdravotnictví ?eské republiky)"
)
base_map
geom_point()
data = my_df,
aes(x = Lon, y = Lat。 color = InitialInfections, size = InitialInfections)
)
scale_color_continuous(name = "Active Cases"/span>, 低 = "粉紅色"。 高 = "red", na. value = "grey50")
scale_size_continuous(name = "Active Cases")
主題(legend.position = "bottom", legend.text。 align = 1, legend. title.align = 0.5)

編輯就我所知,你可以為非sf的坐標添加一個北面的箭頭和比例條。然而,轉換到一個sf物件將自動為比例尺選擇正確的單位。為此,將基圖和點圖層都轉換為sf物件,就像這樣:
library(ggplot2)
library(maps)
library(dplyr)
library(ggspatial)
library(sf)
worldmap <- map_data("world")
worldmap2 <- dplyr:: filter(worldmap, 地區== "捷克共和國") %> %
st_as_sf(coords = c("long"。 "lat")。 crs = 4326) %> %
st_combine() %> %
st_cast("POLYGON"/span>)
base_map <- ggplot(worldmap2)
geom_sf(col = "black"。 填充= "白色"。 尺寸= 1)
annotation_north_arrow()
annotation_scale(location = "tl")
labs()
標題 = "捷克共和國的COVID-19"。 副標題 = "截至2021年7月1日"。 x = "經度"。 y = "Latitude",
caption = "(來源:Ministerstvo zdravotnictví ?eské republiky)"
)
my_df <- My_df %>%
st_as_sf(coords = c("Lon"。 "Lat")。 crs = 4326)
base_map
geom_sf(data = my_df。 aes(color = InitialInfections, 尺寸= InitialInfections))
scale_color_continuous(name = "Active Cases"。 低 = "粉紅色"。 高 = "red", na. value = "grey50")
scale_size_continuous(name = "Active Cases")
主題(legend.position = "bottom", legend.text。 align = 1, legend. title.align = 0.5)

DATA
my_df < -結構(list(Location = c()
"布拉格", "CentralBohemian"。 "SouthBohemian", "SouthBohemian", "Plzen",/span> "KarlovyVary"。 "UstinadLabem"/span>。 "Liberec", "HradecKralove","Pardubice",/span> "Vysocina"。 "SouthMoravian"。 "Olomouc", "Zlin","Moravian-Silesian"
), Lat = c()
50.083333, 50, 49. 083333, 49.7475, 49.
50.230556, 50. 658333, 50.685584, 50. 209167, 49.951136, 49.6079, 49.363161, 49. 593889, 49.29786, 49.988449
), Lon = c()
14.416667,
14.533333,/span> 14. 666667, 13.3775, 12. 8725, 14.041667, 14.537747, 15.831944, 15. 795636, 15.580728, 16. 643175, 17.250833, 17.393135, 17.464759
), InitialVaccinated = c()
252944L, 159560L。 93490L, 82014L,
40129L, 104454L。 59442L, 82074L。 65060L, 66325L。 165250L, 89116L,
80125L, 159490L
), InitialExposed = c()
1380L, 1274L。 1048L, 500L,
50L, 1098L, 506L。 42L, 492L。 820L, 1406L。 1090L, 1116L, 2404L
), InitialInfections = c()
690L,/span> 637L。 524L, 250L。 25L, 549L。 253L, 253L,
21L, 246L, 410L。 703L, 545L。 558L, 1202L
), InitialRecovered = c()
181947L,
226944L, 97405L。 95944L, 43882L。 120416L, 79029L, 102835L, 91729L,
78308L, 151627L。 90887L, 89163L, 174251L
), InitialDead = c()
2736L,
3421L, 1978L, 1912L。 1484L, 2523L。 1280L, 1811L。 1437L, 1375L,
3412L, 1709L。 1594L, 3521L
)), class = "data. , row.names = c()
NA,
-14L
))
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/328614.html
標籤:

