I have been trying to create a world map in R with a heat map overlaid on top of it. I have a dataframe called mydata in which there are 2 columns, the first column is country_code_author1 with ISO3 country codes, and the second column called "n" with the count of how many publications each country has. I attached the code I am using below, but it is only producing a heat patch on the United States when I run it. I attached a picture of my data frame below.
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)
Code/Structure for a mini version of my dataframe
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")
)