|||
因为赖江山老师翻译的《数量生态学——R语言的应用》真的是看不懂,最近开始看起了英文版的 Numerical Ecology with R,这一本是2018年再版的,比上一版确实实用了太多。所以打算将一些重要的笔记记录在此。
大家可以自己去下载他的数据,或者发邮件(2674102796@qq.com)找我要。
加载包,并读取数据。
library(RgoogleMaps)
library(googleVis)
load("D:/R/statistics/NumericalEcologywR-2ed_code_data/NEwR-2ed_code_data/NEwR2-Data/Doubs.RData")
这个时候就可以直接用R包GoogleVis来处理数据。
nom <- latlong$Site
latlong2 <- paste(latlong$LatitudeN, latlong$LongitudeE, sep = ":")
df <- data.frame(latlong2, nom, stringsAsFactors = FALSE)
mymap1 <- gvisMap(df,
locationvar = "latlong2",
tipvar = "nom",
options = list(showTip = TRUE)
)
plot(mymap1)
gvisMap函数画出来的图虽然好看,但是不仅有打码,还不能保存,这在写论文的时候就非常不适用了。所以,在书的源代码中还有另外一种画图的方法。
# This method provides a static image that is viewed in R.
# Map background is fetched from the Internet. The map limits
# are defined by the latitude and longitude of the site
# coordinates.
# Several types of maps are available. Here we use "terrain".
MapBackground(lat = latlong$LatitudeN,
lon = latlong$LongitudeE,
destfile = "bckg",
maptype = "terrain"
)
# Map is loaded into an R object
doubs.map <- ReadMapTile(destfile = "bckg")
# Site latitude-longitude coordinates are added
PlotOnStaticMap(doubs.map,
lat = latlong$LatitudeN,
lon = latlong$LongitudeE,
cex = 0.7,
col = "black",
pch = 19
)
# Plot of labels
TextOnStaticMap(doubs.map,
latlong$LatitudeN - 0.0008 * abs(latlong$LatitudeN),
latlong$LongitudeE,
labels = latlong$Site,
add = TRUE,
cex = 0.5
)
# The size of the points and labels is adjusted by the argument
# cex. The location of the labels has been offset from the
# points by subtraction of small fractions of the latitude.
这种画地图的方法,则更方便保存。也是更加实用的一种画地图方法。怎么样是不是很简单。
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-20 04:17
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社