Uploaded by F.T. Busman

creating a linegraph in R with ggplot

advertisement
Assignment week 1
Fimme Busman s4559118
23-3-2023
Introduction
The data used for this assignment is about small mammels in the dessetrt of New Mexico (USA).
The data was found on the BIOTIME website (Dornelas et al.2018). All the data used is from one
study called “Small Mammal Mark-Recapture Population Dynamics at Core Research Sites”
Figgens et al. (2008). The dataset provides, Amongst other variables, a value for biomass per
plot per year for 27 different species. I could not find a satisfactory explanation for the unit of
the biomass or exactly how the value was obtained, so I have interpreted it as a relative value
that can be used to make a comparrison between different years and obsereve patterns from
year to year. To make it easier to obsereve patterns I have calculated the average biomass from
all plots combined per species per year. I have also filtered out the years with no data from the
dataset. I then pivotted the data to create columns for all the different species to make it
possible to run a correlation test. For these steps I used the following script:
## to get an average for biomas per species per year (1986/2009)
df_average <- df %>%
filter(YEAR>1985,YEAR<2010)%>%
group_by(GENUS_SPECIES,YEAR) %>%
summarise(average=mean(BIOMAS))
## to put the species names above the columns, and create a correltaion mat
rix
df_test <- df_average %>%
pivot_wider(names_from=GENUS_SPECIES, values_from=average)%>%
correlate(df_test)
The observed pattern
An interesting correlation was found in the correlation matrix between the average biomass
values from the species Onychomys leucogaster and Dipodomys merriami. To make the
correlation visible I have first selected only the two species of interest from the whole dataset
and afterwards plotted the values of both species for every year in a line graph. The script used
to create the plot and the plot itself can be seen here:
df_Ol_Dm <- df_average %>%
filter(GENUS_SPECIES== "Onychomys leucogaster" | GENUS_SPECIES=="Dipodomys
merriami")
plot_Ol_Dm <- ggplot(df_Ol_Dm,aes(YEAR,average, color=factor(GENUS_SPECIES)))
+
geom_line(size=1.5) +
labs(x="Year",y="Relative Biomas") +
guides(color=guide_legend(title="Species")) +
theme_bw ()+scale_colour_manual(values=c("#00DF00","#0000DF"))+
ggtitle("Relative Biomas D. merriami and O. leucogaster per year ")
A possible explanation
One explanation for the similarity of the patterns of both species could be that they both react
in a similar way to a change in the environment. To test if a change in temperature over the
years could be the case, I made another dataset with the yearly average temperatures in the
region. The dataset was manually created with data from the website
https://www.wunderground.com/. These averages per year were added to the existing dataset
with Onychomys leucogaster and Dipodomys merriami. And then a new line graph was plotted
using the following script:
df_Ol_Dm_temp <- merge(average_temp,df_Ol_Dm,by="YEAR")
plot_Ol_Dm_temp <- ggplot(df_Ol_Dm_temp,aes(YEAR,average, color=factor(GENUS_
SPECIES)))+
geom_line(size=1.5) +
geom_line(aes(y=average_tempC*10),colour="#EF0000",size=2.5)+
scale_y_continuous(name = "Relative Biomas", sec.axis = sec_axis(~./10, nam
e="Average Temperature (\u00B0C)"))+
labs(x="Year")+guides(color=guide_legend(title="Species")) +
annotate("text",x=1991,y=105,label="Temperature",col="#EF0000",size=3.5)+
annotate("text",x=1991,y=145,label="Onychomys leucogaster",col="#0000DF",si
ze=3.5)+
annotate("text",x=1991,y=177,label="Dipodomys merriami",col="#00DF00",size=
3.5)+
theme_bw ()+scale_colour_manual(values=c("#00DF00","#0000DF"))+
theme(legend.position = "none") +
ggtitle("Relative Biomas D. merriami and O. leucogaster and the average tem
perature per year ")
I used a double y axis (one on the left and one on the right) so the change in temperature is
clearly visible, and it is clear what happens on the same time. I added text to the differnt lines to
specifie what line resembles what data, and i changed the colors to make the lines stand out
more.
From the new graph you can see that the massive drop in biomass from about 1998 is preceded
by a increase in average temperature. This could be a cause of the drop. It is however not
possible to draw any conclusions from this data alone.
References:
-Dornelas M, Antão LH, Moyes F, Bates, AE, Magurran, AE, et al. BioTIME: A database of
biodiversity time series for the Anthropocene. Global Ecol Biogeogr. 2018; 27:760 - 786.
https://doi.org/10.1111/geb.12729
-Friggens, M. (2008) “Sevilleta LTER Small Mammal Population Data”, Albuquerque, NM:
Sevilleta Long Term Ecological Research Site Database: SEV008. Available at:
http://sev.lternet.edu/data/sev-8, accessed 2012.
Download