#VISUALIZING YOUR DATA
rm(list=ls())
# libraries I need (no need to install...)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
compensation <- read.csv('compensation.csv', header = TRUE)
head(compensation)
## Root Fruit Grazing
## 1 6.225 59.77 Ungrazed
## 2 6.487 60.98 Ungrazed
## 3 4.919 14.73 Ungrazed
## 4 5.130 19.28 Ungrazed
## 5 5.417 34.25 Ungrazed
## 6 5.359 35.53 Ungrazed
str(compensation)
## 'data.frame': 40 obs. of 3 variables:
## $ Root : num 6.22 6.49 4.92 5.13 5.42 ...
## $ Fruit : num 59.8 61 14.7 19.3 34.2 ...
## $ Grazing: Factor w/ 2 levels "Grazed","Ungrazed": 2 2 2 2 2 2 2 2 2 2 ...
#making simple plain with ggplot
ggplot(compensation, aes(y=Fruit, x=Root)) +
geom_point()

#transforming the background
ggplot(compensation, aes(y=Fruit, x=Root)) +
geom_point() +
theme_bw()

#INCREASING THE SIZE OF THE POINTS
ggplot(compensation, aes(y=Fruit, x=Root)) +
geom_point(size=4) +
theme_bw()

#ALTERING THE X & Y VARIABLES
ggplot(compensation, aes(y=Fruit, x=Root)) +
geom_point(size=4) +
xlab("Root Biomass") +
ylab("Fruit Production") +
theme_bw()

#ADDING COLOUR & SHAPE TO THE PLOT
ggplot(compensation, aes(y=Fruit, x=Root, colours= Grazing, shape=Grazing)) +
geom_point(size=4)+
xlab("Root Biomass") +
ylab("Fruit Production") +
theme_bw()

#Box-and-whisker plots
ggplot(compensation, aes(x=Grazing, y=Fruit)) +
geom_boxplot() +
xlab("Grazing Treatment") +
ylab("Fruit Production") +
theme_bw()

#addinf raw-data and layers to the plot, look at the plot and comment on biological difference
ggplot(compensation, aes(x=Grazing, y=Fruit)) +
geom_boxplot() +
geom_point(size=4, colour='red', alpha=0.5) +
xlab("Grazing Treatment") +
ylab("Fruit Production") +
theme_bw()

#Distributions: making histograms of numeric variables
#Histogram of fruits
ggplot(compensation, aes(x=Fruit)) +
geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

#reducing binwidth
ggplot(compensation, aes(x=Fruit)) +
geom_histogram(bins = 15)

ggplot(compensation, aes(x=Fruit)) +
geom_histogram(binwidth = 10)

#A NIFTY TOOL: FACETS
#Producing matrix of graphs
#automatically structured by a factor/categorical variable
ggplot(compensation, aes(x=Fruit)) +
geom_histogram(binwidth = 10) +
facet_wrap(~Grazing)
