Package rinat use case: map of iNaturalist project
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
iNaturalist projects are collection of records posted on iNatualist. Now that we have a R package rinat from rOpenSci I thought of playing around with the data. Here is a function I wrote, to quickly map all the records of a project using ggmap package.
library(ggmap)
library(rinat)
inatmap <- function(grpid){
data1=get_inat_obs_project(grpid, type = "observations")
data1=data1[which(!is.na(data1$Latitude)),]
map <-get_map(location =c(min(data1$Longitude),
min(data1$Latitude),
max(data1$Longitude),
max(data1$Latitude)),
messaging = FALSE)
p <-ggplot()
p= ggmap(map)+geom_point(data=data1,
aes(x=as.numeric(Longitude),
y=as.numeric(Latitude)))
p
}
We can used get_inat_obs_project function from rinat package to get all the observation from the specified project. get_map function form ggmap package to download google maps base layer and ggplot function form ggplot2 package to actually plot the map with points.
Now call to the function with a group name will produce a map with all the records in the project.
inatmap("birdindia")
We can use other ggplot options to add title, legend etc. to the map. This is just a simple example.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
