Farm price of coconut in 2017

Monthly farm wholesale price of coconut without husk of Taluk wise for 6 districts from Kasargod to Palakkad during the year 2017.

fwp=read.csv("/Volumes/Apple/Programming/R_DataFiles/RD/fwp_coc_p.csv")

Melting data for creation of plots

library(reshape)
mp=melt(fwp,id=c(1,2))

BOX PLOT using ggboxplot function in ‘ggpubr’ package in R

library(ggpubr)
## Loading required package: ggplot2
## Loading required package: magrittr
ggboxplot(mp,x="District",y="value",color =rgb(0,0.5,1,1), add="jitter")

Adding mean_sd in the box

ggboxplot(mp,x="District",y="value",add="mean_sd",
          fill = "District",
          palette = c("#00AFBB", "#E7B800", "#FC4E07","#BB3099","#EE0099","#0000AC"))

Horizontal orientation of plot

ggboxplot(mp,x="District",y="value",add="jitter",shape="District",
          fill = "District",notch = TRUE,orientation="horizontal",
          palette = c("#00AFBB", "#E7B800", "#FC4E07","#BB3099","#EE0099","#0000AC"))
## notch went outside hinges. Try setting notch=FALSE.

Jitter shape according to “District”

ggboxplot(mp,x="District",y="value",add="jitter",shape="District",
          notch = TRUE,color="District",
          palette = c("#00AFBB", "#E7B800", "#FC4E07","#BB3099","#EE0099","#0000AC"))
## notch went outside hinges. Try setting notch=FALSE.

Add Median_range

ggboxplot(mp,x="District",y="value",add="median_range",
          notch = TRUE,color="District",
          palette = c("#00AFBB", "#E7B800", "#FC4E07","#BB3099","#EE0099","#0000AC"))
## notch went outside hinges. Try setting notch=FALSE.

Changing the order of districts in x-axis

ggboxplot(mp,x="District",y="value",add="median_range",
          notch = TRUE,color="District",
          palette = c("#00AFBB", "#E7B800", "#FC4E07","#BB3099","#EE0099","#0000AC"),
          order=c("Kasargod","Kannur","Wayand","Kozhikode","Malappuram","Palakkad"))
## notch went outside hinges. Try setting notch=FALSE.

Adding ‘dotplot’ in box

ggboxplot(mp,x="District",y="value",add="dotplot",
          notch = TRUE,color="District",
          palette = c("#00AFBB", "#E7B800", "#FC4E07","#BB3099","#EE0099","#0000AC"),
          order=c("Kasargod","Kannur","Wayand","Kozhikode","Malappuram","Palakkad"))
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## notch went outside hinges. Try setting notch=FALSE.

Adding ‘point’ in boxes

ggboxplot(mp,x="District",y="value",add="point",
          notch = TRUE,color="District",
          palette = c("#00AFBB", "#E7B800", "#FC4E07","#BB3099","#EE0099","#0000AC"),
          order=c("Kasargod","Kannur","Wayand","Kozhikode","Malappuram","Palakkad"))
## notch went outside hinges. Try setting notch=FALSE.

Selecting two districts only by using ‘select’ property.Here even though all 6 districts are mentioned in the codes, the only selected districts with the first two colors in palette will be assigned to the boxes.

ggboxplot(mp,x="District",y="value",add="point",
          notch = TRUE,color="District",
          palette = c("#00AFBB", "#E7B800", "#FC4E07","#BB3099","#EE0099","#0000AC"),
          order=c("Kasargod","Kannur","Wayand","Kozhikode","Malappuram","Palakkad"),
          select = c("Malappuram","Palakkad"))

Changing the width of boxes to 0.5. Notch is removed.

ggboxplot(mp,x="District",y="value",add="point",
          notch = FALSE,color="District",width=0.5,
          palette = c("#00AFBB", "#E7B800", "#FC4E07","#BB3099","#EE0099","#0000AC"),
          order=c("Kasargod","Kannur","Wayand","Kozhikode","Malappuram","Palakkad"))

Adding ‘mean-se’ and chnage the size to 0.8, color= green using list.params property.

ggboxplot(mp,x="District",y="value",add="mean_se",
          add.params = list(color='green',size=0.8),
          notch = FALSE,color="District",width=0.5,
          palette = c("#00AFBB", "#E7B800", "#FC4E07","#BB3099","#EE0099","#0000AC"),
          order=c("Kasargod","Kannur","Wayand","Kozhikode","Malappuram","Palakkad"))

Adding ‘error bar’ in each box using the Argument ‘bxp.errorbar’ and fill the box with color of ‘District’

ggboxplot(mp,x="District",y="value",add="mean_se",
          add.params = list(color='green',size=0.8),fill = "District",
          notch = FALSE,color="District",width=0.5,bxp.errorbar = TRUE,
          palette = c("#00AFBB", "#E7B800", "#FC4E07","#BB3099","#EE0099","#0000AC"),
          order=c("Kasargod","Kannur","Wayand","Kozhikode","Malappuram","Palakkad"))

Box Plot for 11 years district wise Farm Price data

ggboxplot using the data of farm wholesale price of all districts from 2007 to 2017

fd=read.csv("/Volumes/Apple/Programming/R_DataFiles/RD/MC_fwp_coc.csv")

Melting the dataframe using reshape2 package

names(fd)=tolower(names(fd))
library(reshape2)
## 
## Attaching package: 'reshape2'
## The following objects are masked from 'package:reshape':
## 
##     colsplit, melt, recast
mfd=melt(fd,id=c(1,2,3),na.rm = TRUE)

Box plot of all districts (of all 11 years)

library(ggpubr)
ggboxplot(mfd,x="district",y="value",color = 'green',fill = "district")+
          theme(axis.text.x = element_text(angle=90))

Another way to change the orientation of x-axis text

p=ggboxplot(mfd,x="district",y="value",color = 'blue',fill = "district",
            add = "mean_se")
p+rotate_x_text(angle = 90)

Boxplot of all years subgrouping with districts.

p=ggboxplot(mfd,x="year",y="value",fill = 'year',bxp.errorbar = TRUE,color = "district")
p+rotate_x_text(angle = 90)

Not filling the boxes, only coloring the outline of boxes (including subgrouped districts)

p=ggboxplot(mfd,x="year",y="value",color = "district")
p+rotate_x_text(angle = 90)

Boxplot of 2015 farm price

Extracting data for the year 2015 from the dataframe of 11 years data and draw boxplot

fd2=fd[fd$year %in% c("2015"),]
mfd2=melt(fd2,id=c(1,2,3),na.rm=TRUE)
library(ggpubr)
gb=ggboxplot(mfd2,x="district",y="value",color='gray',fill="district",
             title="Farm price of coconut in 2015")
gb+rotate_x_text(90)

gg Scatter Plot using ggpunr package

Data: Farm wholesale price of coconut without husk for the year 2017 ggscatterplot with ‘ellipse’=TRUE

fwp=read.csv("/Volumes/Apple/Programming/R_DataFiles/RD/fwp_coc_ggp.csv")
d1=fwp[22:38,c(1,3:5)]
ggscatter(d1,x="Jan",y="Feb",color = "District",
          palette = c("#00AFBB", "#E7B800", "#FC4E07"),
          ellipse = TRUE,mean.point = TRUE,star.plot = FALSE)

Changing the ellipse type to ‘confidence’ and ‘star.plot’= TRUE

ggscatter(d1,x="Jan",y="Feb",color = "District",
          palette = c("#00AFBB", "#E7B800", "#FC4E07"),
          ellipse = TRUE,ellipse.type = "confidence",
          mean.point = TRUE,star.plot = TRUE,ggtheme = theme_void())

Using randomcolor funtion to color the graph.

randomcolor=grDevices::colors()[grep('gr(ale)y',grDevices::colors(),invert = T)]
ggscatter(d1,x="Jan",y="Feb",color = "District",
          palette = sample(randomcolor),
          label="District",repel = FALSE)

Labeling of each point with the District name inside the plot. Here ‘repel’=TRUE means overlaping of point namew will be avoided.

ggscatter(d1,x="Jan",y="Feb",color = "District",
          palette = c("#00AFBB", "#E7B800", "#FC4E07"),
          label="District",repel = TRUE)

ggdensity Plot in R ggpbur package

Data: Farm wholesale price of coconut in 2017. Here the data contains District wise Taluk wise farm price for each month.

fwp=read.csv("/Volumes/Apple/Programming/R_DataFiles/RD/MC_fwp_coc.csv")
fwpd=data.frame(fwp)
fwpd2=fwpd[1:25,]
library(reshape2)
names(fwpd2)=tolower(names(fwpd))
meltfwp=melt(fwpd2,id=c("year","district","taluk"))
d7=meltfwp[1:300,4:5]
# ggdensity plotting
library(ggpubr)
ggdensity(d7,x="value",add = "mean",rug =FALSE,color = 'deeppink')
## Warning in (function (mapping = NULL, data = NULL, ..., xintercept, na.rm = FALSE, : Using both `xintercept` and `mapping` may not have the desired result as mapping is overwritten if `xintercept` is specified

ggdensity plot with ‘rug’ property= TRUE

ggdensity(d7,x="value",add = "mean",rug = TRUE,color = 'steelblue')
## Warning in (function (mapping = NULL, data = NULL, ..., xintercept, na.rm = FALSE, : Using both `xintercept` and `mapping` may not have the desired result as mapping is overwritten if `xintercept` is specified

Color with variable. Here the molten data using reshape2 package is having the variable as months from Jan to Dec of the year 2007. So the color will be different for each district. Further subgrouping of density plot month wise.

ggdensity(d7,x="value",add = "mean",rug = TRUE,
          color="variable",title="Month wise farm price of coconut in 2007")

Here instead of the system generated colors for each month, random color generated is used. So for every time of processing the code, different colors will be generated. Here also, fill the density curves with transparent colors.

randomcolor=grDevices::colors()[grep('gr(ale)y',grDevices::colors(),invert = T)]
ggdensity(d7, x = "value",add = "mean", rug = TRUE,
          color = "variable", fill = "variable",
          palette = sample(randomcolor,12),
          title = "Density plot of month wise farm price of coconut in 2017 in Kerala",
          font.title=12)

Now we are using the month wise average price for each district (average price of all Taluks in that district) for the year 2017 to plot the density plot using R ggpbur package. So for each month there will be 14 average prices (of 14 districts).

fwp=read.csv("/Volumes/Apple/Programming/R_DataFiles/RD/fwp_coc_ggp.csv")
d8=fwp[1:47,c(1,3:14)]
# Melt data using reshape2
library(reshape2)
dm=melt(d8,1)
# ggdensity plotting
library(ggpubr)
dc2=dcast(dm,variable~District,mean)
dm2=melt(dc2,1)
month=dm2$variable
price=dm2$value
dfm=data.frame(month,price)
ggdensity(dfm,x="price",add="median",rug=TRUE,color = "darkorange")
## Warning in (function (mapping = NULL, data = NULL, ..., xintercept, na.rm = FALSE, : Using both `xintercept` and `mapping` may not have the desired result as mapping is overwritten if `xintercept` is specified

library(ggpubr)
ggdensity(dfm,x="price",add = "mean",rug = TRUE,
          color="month",title = "Month wise average price of coconut in Kerala in 2017",
          font.title=list(size=11,color='blue',face="bold"))

library(RColorBrewer)
ggdensity(dfm, x = "price",
          add = "mean", rug = TRUE,
          color = "month", fill = "month",
          palette = c("#00AFBB", "#E7B800","#0af7fa","#0afa75","#d0fa0a","#86992f",
                      "#f581ad","#b94e76","#1b97de","#445965","#c7f29d","#bb79f3"))

randomcolor=grDevices::colors()[grep('gr(ale)y',grDevices::colors(),invert = T)]
ggdensity(dfm, x = "price",
          add = "mean", rug = TRUE,
          color = "month", fill = "month",
          palette = sample(randomcolor,12))