Box plot in R using ggplot2: Video Tutorial


Download R script file: Download

R Script (copy and paste the code in R studio):
To learn more about R: Click here

#Writer: Rohan Byanjankar
#How to create a box plot in R
#Import data
#Import readxl ggplot2 ggthemes package
#Importing excel data
#install.packages("readxl","ggplot2", "ggthemes") #Remove '#' to activate the code

library(readxl)#ctrl+enter
library(ggplot2)
library(ggthemes)

#<- = alt+-
datafile <- read_excel("give file path (change \ with /")

#creating a box plot of per capita deposit by province
#attaching dataset
attach(datafile)
#creating boxplot
boxplot1 <- ggplot(datafile,aes(x=Province,y=log(per_deposit),fill=Province))+ geom_boxplot(outlier.colour = "red",outlier.shape = 8,outlier.size = 5)+
stat_boxplot(geom = 'errorbar')+
ggtitle("Box plot of per capita deposit by province")+
xlab("Province")+
ylab("Per capita deposit in log scale")+
labs(caption = "Source:Nepal Rastra Bank (2020)")+
theme_economist()
boxplot1
#ctrl+shift+6
To learn more about RClick here

Post a Comment

0 Comments