I'm pretty new to R and I am trying to map the distribution of an ant species in Argentina using the adm1 (or state) divisions.
I have downloaded data from the GADM website and I have a csv file that I've created that contains info saying whether the species is present or absent in each adm1. Even though I don't have a gradient can I still make a choropleth? If not, what other types of maps could I use?
I've looked at several sites including Infomaps using R, How to make choropleths in R, and the Choropleth Map Challenge, which have been really helpful but they all have numeric data and I'm using a present(1) or absent(0) column. The different packages I've tried are sp
(with RColorBrewer
), ggplot2
, rgeos
, and maptools
.
Here is the code I have so far:
library(sp)
library(RColorBrewer)
write.csv(atr, "atr_data.csv")
atr_data<-read.csv("atr_data.csv", header=TRUE)
spcode country_code adm1_code newcol
1 atr VEN VE.AR 0
2 atr PRY PY.CE 0
3 atr PAN PA.CL 0
4 atr PAN PA.CL 0
5 atr PAN PA.PN 0
6 atr PAN PA.PN 0
I'm in the process of making a column with the full adm1 names instead of the codes so that it will match up with the GADM file (so I haven't written the code to merge the data yet).
#to retrieve map for Argentina ARG
con <- url("http://gadm.org/data/rda/ARG_adm1.RData")
print(load(con))
close(con)
#to generate random colors on map
col = rainbow(length(levels(gadm$NAME_1)))
spplot(gadm, "NAME_1", col.regions=col, main="ARG Regions", colorkey = FALSE, lwd=.4,col="white")
#this piece of code is a mess
col_no <- as.factor(as.numeric(atr_data$newcol[order],
c(0,1)))
levels(col_no)<- c("0", "1")
gadm$col_no <- col_no
myPalette<-brewer.pal(3, "Purples")
spplot(gadm, "col_no", col=grey(.9),
col.regions=myPalette,
main="Distribution of Atratus in Argentina")
Any help would be greatly appreciated, thanks!