* A package termed as a grammar of Graphics for visualization of data.
#Remove the environment variable
rm(list=ls())
#Load Packages
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)
#Load Compensation Data File
library(readr)
compensation = read_csv("D:\\R Course\\DataAnalysis\\Data\\datasets-master\\compensation.csv")
## Rows: 40 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): Grazing
## dbl (2): Root, Fruit
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
ggplot(compensation,aes(x=Root,y=Fruit))+geom_point()
#Use black and white background
ggplot(compensation,aes(x=Root,y=Fruit))+geom_point()+theme_bw()
#Increase the size of the point
ggplot(compensation,aes(x=Root,y=Fruit))+geom_point(size=3)+theme_bw()
#Add axis labels
ggplot(compensation,aes(x=Root,y=Fruit))+geom_point(size=3)+xlab("Root Biomass")+ylab("Fruit Production")+theme_bw()
#Add colors for different groups based on a factor
ggplot(compensation,aes(x=Root,y=Fruit,color=Grazing))+geom_point(size=3)+xlab("Root Biomass")+ylab("Fruit Production")+theme_bw()
ggplot(compensation,aes(x=Grazing,y=Fruit))+geom_boxplot()+xlab("Grazing Treatment")+ylab("Fruit Production")+theme_bw()
#Add raw data changing size, color and transparancy
ggplot(compensation,aes(x=Grazing,y=Fruit))+geom_boxplot()+geom_point(size=3,color='red',alpha=.5)+xlab("Grazing Treatment")+ylab("Fruit Production")+theme_bw()
ggplot(compensation,aes(x=Fruit))+geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#Adding custom binwidth
ggplot(compensation,aes(x=Fruit))+geom_histogram(binwidth = 15)
#Choosing no of bins
ggplot(compensation,aes(x=Fruit))+geom_histogram(bins=10)
#Faceting based on some factor
ggplot(compensation,aes(x=Fruit))+geom_histogram(bins=10)+facet_wrap(~Grazing)
##### Saving the figure
ggsave("MyFirstFigure.png")
## Saving 7 x 5 in image