Skip to content

Instantly share code, notes, and snippets.

@luisDVA
Created Nov 23, 2015
Embed
What would you like to do?
script for plotting mammal research data
library(ggplot2)
library(dplyr)
library(gridExtra)
library(rphylopic)
MammalDisc <- read.csv(file = "https://raw.githubusercontent.com/luisDVA/codeluis/master/mammalDiscoveries.csv",stringsAsFactors = FALSE)
# plot search results by order for all orders
ggplot(MammalDisc,aes(results,reorder(sp,descYear)))+
geom_point() + theme_minimal() + theme(axis.text.y = element_blank())+
facet_wrap( ~ order,scales = "free", ncol=2)+ylab("species")
# plot search results for entire dataset
ggplot(MammalDisc,aes(descYear,results))+geom_point(pch=21,size=4,position = "jitter")+
theme_minimal()+xlab("description year")+ylab("number of search results")
# plot search results by order for orders with >2 new species
MammalDisc %>% group_by(order) %>% mutate(count=n()) %>%
filter(count>2) %>%
ggplot(aes(results,reorder(sp,descYear)))+
geom_point() + theme_minimal() + theme(axis.text.y = element_blank())+
facet_wrap( ~ order,scales = "free", ncol=2)+ylab("species")
# plots for Rodentia and Chiroptera
# get background imaged from Phylopic
imgRat <- image_data("0f6af3d8-49d2-4d75-8edf-08598387afde", size = "512")[[1]]
imgBat <- image_data("18bfd2fc-f184-4c3a-b511-796aafcc70f6", size = "512")[[1]]
# create plot objects
ratPlot <- MammalDisc %>% filter(order=="Rodentia") %>%
ggplot(aes(results,reorder(sp,descYear)))+
geom_text(aes(label=descYear))+
theme_minimal()+
add_phylopic(imgRat) +xlab("")+ylab("")
batPlot <- MammalDisc %>% filter(order=="Chiroptera") %>%
ggplot(aes(results,reorder(sp,descYear)))+
geom_text(aes(label=descYear))+
theme_minimal()+
add_phylopic(imgBat)+xlab("")+ylab("")
# plot side by side
grid.arrange(ratPlot, batPlot, ncol=2,
bottom="Google Scholar hits",
left= "species",widths=c(1,1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment