###################################################################
############# Module 5, Basics of data visualization ##############
###################################################################
## Lesson 8, Part 1: Introduction to data visualization (scatterplots and boxplots)


###################################
##### UPLOAD DATA
# First, load the data. I sourced the rest of the data
# for this course from the 'Ecological Data Wiki" "ecologicaldata.org"
# that houses a repository of links to open-source datasets with accompanying references.
# For this first part I used data from 
# Lislevand et al. 2007: http://www.esapubs.org/archive/ecol/E088/096/default.htm

avian_data <- read.csv("data/avian_mating_data_clean.csv")

head(avian_data)

###################################
##### THE 'plot()' and 'hist()' FUNCTIONS
# The most common and basic function you will use when plotting is plot()

plot()

egg_mass <- avian_data$egg_mass_g
female_mass <- avian_data$female_bodymass_g

plot(x=female_mass, y=egg_mass)

plot(egg_mass_g ~ female_bodymass_g, data=avian_data)

names(avian_data)

plot(log(egg_mass_g) ~ clutch_size, data=avian_data)

hist(log(avian_data$egg_mass_g), breaks=100)

table(avian_data$mating_system)

###################################
##### THE 'boxplot()' FUNCTION
# The next most common function for plotting is the boxplot function

boxplot(log(egg_mass_g) ~ mating_system, data=avian_data)

head(avian_data)

larger_female <- (avian_data$female_bodymass_g - avian_data$male_bodymass_g) > 0

boxplot(log(egg_mass_g) ~ larger_female, data=avian_data)


###################################
##### SUMMARY
# - plot(), hist(), boxplot() functions


