今天教大家画一个物种地理位置分布点图,需要提前安装好下面这几个R包。
library(ggmap)
library(sp)
library(maptools)
library(maps)
直接上代码:
mydata<-read.table("1.csv",header=TRUE,sep=",") #第一列是latitude纬度,第二列是longitude经度,第三列是数量
具体示范文件如下所示:
latitude longitude number
33.939 67.71 1
47.516 14.55 1
23.685 90.356 1
32.718 114.236 1
后面代码如下:
visit.x<-mydata$longitude
visit.y<-mydata$latitude
library(ggmap)
红色的信息不用管
Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
Please cite ggmap if you use it! See citation("ggmap") for details.
Attaching package: ‘ggmap’
The following objects are masked from ‘package:ggtree’:
inset, theme_inset
library(sp)
Attaching package: ‘sp’
The following object is masked from ‘package:IRanges’:
%over%
library(maptools)
Checking rgeos availability: FALSE
Please note that 'maptools' will be retired by the end of 2023,
plan transition at your earliest convenience;
some functionality will be moved to 'sp'.
Note: when rgeos is not available, polygon geometry computations in maptools depend on gpclib,
which has a restricted licence. It is disabled by default;
to enable gpclib, type gpclibPermit()
library(maps)
Attaching package: ‘maps’
The following object is masked from ‘package:purrr’:
map
The following object is masked from ‘package:cluster’:
votes.repub
mp<-NULL #定义一个空的地图
mapworld<-borders("world",colour = "gray50",fill="white") #绘制基本地图
mp<-ggplot()+mapworld+ylim(-60,90)
mp2<-mp+geom_point(aes(x=visit.x,y=visit.y,size=mydata$number),color="darkorange")+scale_size(range=c(1,1))
mp3<-mp2+theme(legend.position = "none") #将图例去掉
mp3
新鲜的物种分布点图出炉了,大家快去试试吧。
image.png
image
生信漫谈
生信漫谈,认识生信,学习生信,跨越生信入门路上的障碍,从而利用生信技术解决科研学习路上的绊脚石!
网友评论