library(maps)
library(ggplot2)
library(tidyverse)
Possible errors:
Workaround install.packages("vctrs")
Utilize the world map data package
world_map<-map_data("world")
The result is as follows
Mapping with world map data
ggplot(world_map, aes(x = long, y = lat, group = group)) +
geom_polygon(fill="white", colour = "gray50") +
theme_classic()
Visual data display is required. For convenience, only some countries are shown here:
import excel data
install.packages("xlsx")
library(xlsx)
a<-read.xlsx("C:/Users/Administrator/Desktop/example.xlsx",1)
The imported data set a is as shown in the figure below
Add the latitude and longitude data of the world_map to the data set a according to the same country splicing
left_join(a,world_map,by="region")->a
The data splicing results are as follows:
Use the spliced data a to draw a heat map
ggplot(a, aes(x = long, y = lat, group = group)) +
geom_polygon(aes(fill= f), colour = "white")
The drawing results are as follows:
Adjust graph color
ggplot(a, aes(x = long, y = lat, group = group))+theme_linedraw()+geom_polygon(aes(fill=f), colour = "white")+scale_fill_gradient(low = "lightblue", high="steel blue")
Adjust line color to black
ggplot(a, aes(x = long, y = lat, group = group))+theme_linedraw()+geom_polygon(aes(fill=f), colour = "black")+scale_fill_gradient(low = "lightblue", high="steel blue")
adjust the background
ggplot(a, aes(x = long, y = lat, group = group))+theme_minimal()+geom_polygon(aes(fill=f), colour = "white")+scale_fill_gradient(low = "lightblue", high="steel blue")
change color
ggplot(a, aes(x = long, y = lat, group = group))+theme_minimal()+geom_polygon(aes(fill=f), colour = "white")+scale_fill_gradient(low = "aquamarine", high="aquamarine4")