R语言做图

library(maps)
library(mapdata)
library(ggplot2)
library(sp)
library(dplyr)
library(ggthemes)
library(REmap)
library(recharts)
library(ggalt)

knitr::opts_chunk$set(echo = TRUE)
rm(list=ls())
library(readxl)

rm(list=ls())
library(readxl)

exit <- read_excel("G:/R default work directory/exit.xlsx")
entry <- read_excel("G:/R default work directory/entry.xlsx")
gross <- read_excel("G:/R default work directory/gross.xlsx")
names(exit)=c('country','counts','lat','long')
names(entry)=c('country','counts','lat','long')
names(gross)=c('country','counts','lat','long')

map("world", col = "red4", panel.first = grid())
for (i in 1:12) {
points(exit$long[i], exit$lat[i], cex = 1.5, pch = 16)}
title('变动员工分布图')

exit$long=as.numeric(as.character(exit$long))
exit$lat=as.numeric(as.character(exit$lat))
exit$counts=as.numeric(as.character(exit$counts))
entry$long=as.numeric(as.character(entry$long))
entry$lat=as.numeric(as.character(entry$lat))
entry$counts=as.numeric(as.character(entry$counts))
mp<-NULL #定义一个空的地图 

mapworld<-borders("world",colour = "gray50",fill="white") #绘制基本地图 

mp<-ggplot()+mapworld+ylim(-90,90) + geom_point(aes(x=gross$long, y=gross$lat,size=gross$counts), color="red", alpha=0.5) + scale_size(range=c(2,9))+xlab("经度")+ylab("维度") + labs(size = "变动员工数量") + theme (legend.position = "top",legend.text = element_text( face= "bold" ,size=10)) 

mp #将地图呈现出来

#REmap#

exit<-exit[,-c(3,4)]
as.numeric(exit$counts)

a=exit$counts/100

data = data.frame(country = exit$country, value=exit$counts)
out = remapC(data, maptype = "world", color = 'red')
plot(out)

#Recharts#

exit<-exit[,-c(3,4)]
exit$country[1]<-"United States of America"
worldcounts<-exit

echartr(worldcounts, country, counts, type="map_world", subtype="move + scale") %>% setDataRange(splitNumber=0, color=getColFromPal('rainbow')) %>% setTitle("离职员工分布")

猜你喜欢

转载自blog.csdn.net/weixin_42067401/article/details/106750529