Craig F. Barrett
April 07, 2021
Department of Biology
West Virginia University
Morgantown, WV USA 26506
cfb0001@mail.wvu.edu
## install packages, load libraries
# install.packages(c("rworldmap","gridExtra"))
library(rworldmap)
package 㤼㸱rworldmap㤼㸲 was built under R version 4.0.3Loading required package: sp
### Welcome to rworldmap ###
For a short introduction type : vignette('rworldmap')
library(ggplot2)
library(gridExtra)
package 㤼㸱gridExtra㤼㸲 was built under R version 4.0.3
Attaching package: 㤼㸱gridExtra㤼㸲
The following object is masked from 㤼㸱package:dplyr㤼㸲:
combine
library(RColorBrewer)
package 㤼㸱RColorBrewer㤼㸲 was built under R version 4.0.3
# load US and Asia data -- awn proportions by centroid
setwd(choose.dir())
chjp<-read.csv("chjp.csv")
chjp<-as.data.frame(chjp)
## filter data for Asian specimens only
asia <- chjp %>% filter(cont == "Asia")
## filter for US data
us <- chjp %>% filter(cont == "USA")
# plot Asian pie charts
asiamap <- mapPies(dF =asia,
nameX="lon",
nameY="lat",
nameZs =c("awnless", "awned"),
zColours=c("red","blue"),
ratio=1,
oceanCol = "gray80",
landCol = "white",
symbolSize=2,
lwd=2,
borderCol="black",
addSizeLegend=T,
addCatLegend=T,
#mapRegion="asia",
xlim=c(70,141),
ylim=c(15,50))
symbolMaxSize= 1.42 maxSumValues= 44 symbolScale= 0.2140731
List of 2
$ x: num [1:100] 75.7 75.7 75.7 75.6 75.6 ...
$ y: num [1:100] 46.2 46.4 46.6 46.7 46.9 ...
# plot US pies
usmap <- mapPies(dF =us,
nameX="lon",
nameY="lat",
nameZs =c("awnless", "awned"),
zColours=c("red","blue"),
ratio=1,
oceanCol = "gray80",
landCol = "white",
symbolSize=4,
lwd=2,
borderCol="black",
addSizeLegend=T,
addCatLegend=T,
#mapRegion="asia",
xlim=c(-90,-70),
ylim=c(26,45))
symbolMaxSize= 0.4 maxSumValues= 100 symbolScale= 0.04
List of 2
$ x: num [1:100] -95.5 -95.5 -95.5 -95.5 -95.5 ...
$ y: num [1:100] 42.6 42.7 42.8 42.9 43 ...
uschinaplot2 <- ggplot(chjp, aes(x=lat, y=prop, col=cont, shape=cont)) +
geom_point(aes(size=tot))+
scale_color_manual(values=c('red','blue'))+
geom_smooth(method=lm, aes(fill=cont))
uschinaplot2 + scale_size(range = c(10,20))
scale_color_gradient(low = "red", high = "blue")
<ScaleContinuous>
Range:
Limits: 0 -- 1