我一直在嘗試在 R 中創建一個世界地圖,上面覆寫著一個熱圖。我有一個名為 mydata 的資料框,其中有 2 列,第一列是 country_code_author1,帶有 ISO3 國家代碼,第二列是“n”,表示每個國家/地區擁有的出版物數量。我在下面附上了我正在使用的代碼,但是當我運行它時,它只會在美國產生一個熱補丁。我在下面附上了我的資料框的圖片。
library(maps)
library(ggplot2)
mydata <- df_country_count_auth1
world_map <- map_data("world")
world_map <- subset(world_map, region != "Antarctica")
ggplot(mydata)
geom_map(
dat = world_map, map = world_map, aes(map_id = region),
fill = "white", color = "#7f7f7f", size = 0.25
)
geom_map(map = world_map, aes(map_id = country_code_author1, fill = n), size = 0.25)
scale_fill_gradient(low = "#fff7bc", high = "#cc4c02", name = "Worldwide Publications")
expand_limits(x = world_map$long, y = world_map$lat)
我的資料框的迷你版本的代碼/結構
myData <-
structure(
list(
country_code_author1 = c(
"AGO",
"AIA",
"ALB",
"ARE",
"ARG",
"ARM",
"ATG",
"AUS",
"AUT",
"AZE"
),
n = c(3L, 1L,
11L, 3L, 38L, 1L, 4L, 240L, 98L, 23L)
),
row.names = c(NA,-10L),
groups = structure(
list(
country_code_author1 = c(
"AGO",
"AIA",
"ALB",
"ARE",
"ARG",
"ARM",
"ATG",
"AUS",
"AUT",
"AZE"
),
.rows = structure(
list(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L),
ptype = integer(0),
class = c("vctrs_list_of",
"vctrs_vctr", "list")
)
),
row.names = c(NA,-10L),
class = c("tbl_df",
"tbl", "data.frame"),
.drop = TRUE
),
class = c("grouped_df",
"tbl_df", "tbl", "data.frame")
)

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/381253.html
