##########################
##                      ##
## Walk-through Example ##
##                      ##  
##########################

one<- c(22,25,27,23) # input lists of values, assigning each list a name
two<- c(41,46,59,38)
three<- c(66,72,51,78)
four<- c(82,73,73,84)
five<- c(79,68,74,70)

boxplot(one,two,three,four,five, # create boxplots of all five lists in the order 1-5
        ylab = "Seeds germinating per box", # set y-axis label
        xlab = "Amount of water", # set x-axis label
        ylim=c(0,100), yaxs = "i", # set y-axis limits
        names=c(1,2,3,4,5)) # assign labels for each box on the x-axis

boxplot(one,two,three,four,five, 
        ylab = "Seeds germinating per box", 
        xlab = "Amount of water",
        ylim=c(0,100), yaxs = "i",
        names=c(1,2,3,4,5),
        col="green") # substitute any colour you like in place of "green"

boxplot(one,two,three,four,five, 
        ylab = "Seeds germinating per box", 
        xlab = "Amount of water",
        ylim=c(0,100), yaxs = "i",
        names=c(1,2,3,4,5),
        col=c("lightskyblue1","cadetblue2","cornflowerblue",
              "dodgerblue4","darkblue")) # select 5 sequential colours (getting darker in hue)
        
seeds <- read.table(file.choose(), header = T, sep = ",") # load in bigger data set (seed_data.csv)
                                                          # assigning it the name 'seeds'

View(seeds) # view the data

uncovered <- subset(seeds, treatment=="uncovered") # subset the 'uncovered' boxes
covered <- subset(seeds, treatment=="covered") # subset the 'covered' boxes

boxplot(uncovered$germinated~uncovered$water, # draw boxplots for the 'uncovered' data
        ylab = "Seeds germinating per box", 
        xlab = "Amount of water",
        ylim=c(0,100), yaxs = "i",
        boxwex=0.27, # a scaling factor that will make the boxes narrower than their default 
        at = 1:5 - 0.15, # where we want the boxes placed along the x-axis (slightly to the left)
        xlim=c(0.5,5.5),
        xaxt="n", # keep x-axis blank for now
        col="cornflowerblue")
par(new=TRUE) # prepare to add the following code to the existing plot
boxplot(covered$germinated~covered$water, # draw boxplots for the 'covered' data on the same plot
        ylab="",xlab="", # keep axis labels blank as their details are already included
        ylim=c(0,100), yaxs = "i",
        boxwex=0.27,
        at = 1:5 + 0.15, # where we want the boxes placed along the x-axis (slightly to the right)
        xlim=c(0.5,5.5),
        xaxt="n",
        yaxt="n", # keep y-axis blank as its details are already included
        col="forestgreen")
axis(side=1, # add an x-axis to the bottom of the plot
     at=1:5, # position tick marks at coordinates 1-5
     labels=c(1:5)) # labels tick marks as 1-5
legend("topleft", # add a legend to the top left of the plot
       inset=.02, # pull the legend in from the very edge of the plot a bit,
       bty="n", # do not encase the legend in a box
       legend=c("Uncovered","Covered"), # give the names for the legend
       fill=c("cornflowerblue","forestgreen")) # give the corresponding colours for those names

install.packages("viridisLite") # install the package viridisLite needed for viridis
install.packages("viridis") # install the package viridis
library(viridisLite) # activate the package viridisLite
library(viridis) # activate the package viridis

colourchoice<-viridis(2) # create a list of 2 accessible colours from viridis
colourchoice # view the codes of the 2 chosen colours

boxplot(uncovered$germinated~uncovered$water, 
        ylab = "Seeds germinating per box", 
        xlab = "Amount of water",
        ylim=c(0,100), yaxs = "i",
        boxwex=0.27,at = 1:5 - 0.15,
        xlim=c(0.5,5.5),xaxt="n",
        col=colourchoice[1]) # use the first colour from our accessible colour list
par(new=TRUE)
boxplot(covered$germinated~covered$water, 
        ylab="",xlab="",
        ylim=c(0,100), yaxs = "i", 
        boxwex=0.27,at = 1:5 + 0.15,
        xlim=c(0.5,5.5),
        xaxt="n",yaxt="n",
        col=colourchoice[2]) # use the second colour from our accessible colour list
axis(side=1, at=1:5, labels=c(1:5)) 
legend("topleft", inset=.02, bty="n", c("Uncovered","Covered"), 
       fill=colourchoice) # use our accessible list to fill the legend colours

# Save plot as an image

# Save R script















