Reading data from csv file

data=read.csv("/Volumes/Apple/Programming/R_DataFiles/RD/Agri_Area.csv")

Summary of data

summary(data)
##        Crop        Kerala       Thiruvananthapuram     Kollam     
##  Arecanut: 1   Min.   :  2603   Min.   :    0      Min.   :    0  
##  Banana  : 1   1st Qu.: 39730   1st Qu.:  962      1st Qu.:  606  
##  Cardamom: 1   Median : 69405   Median : 2119      Median : 2334  
##  Cashew  : 1   Mean   :135739   Mean   : 8825      Mean   : 8024  
##  Coconut : 1   3rd Qu.: 92969   3rd Qu.: 6853      3rd Qu.: 5651  
##  Coffee  : 1   Max.   :790223   Max.   :72340      Max.   :51834  
##  (Other) :11                                                      
##  Pathanamthitta      Alappuzha          Kottayam         Idukki     
##  Min.   :    0.0   Min.   :    0.0   Min.   :    0   Min.   :  188  
##  1st Qu.:  610.5   1st Qu.:  377.2   1st Qu.:  309   1st Qu.: 1147  
##  Median : 1756.5   Median : 1565.0   Median : 2879   Median : 6224  
##  Mean   : 5518.8   Mean   : 5440.9   Mean   : 4971   Mean   :12255  
##  3rd Qu.: 2621.2   3rd Qu.: 3161.2   3rd Qu.: 4414   3rd Qu.:16546  
##  Max.   :50880.0   Max.   :33227.0   Max.   :26849   Max.   :42694  
##  NA's   :1         NA's   :1         NA's   :1                      
##    Eranakulam         Thrissur        Palakkad       Malappuram    
##  Min.   :    0.0   Min.   :    0   Min.   :  576   Min.   :     0  
##  1st Qu.:  339.5   1st Qu.:  530   1st Qu.: 1958   1st Qu.:  1816  
##  Median : 4108.0   Median : 1790   Median : 4833   Median :  4706  
##  Mean   : 6505.2   Mean   : 9190   Mean   :14590   Mean   : 13462  
##  3rd Qu.: 4821.5   3rd Qu.: 6271   3rd Qu.:10006   3rd Qu.:  8690  
##  Max.   :60140.0   Max.   :81602   Max.   :81120   Max.   :103391  
##  NA's   :2                                         NA's   :1       
##    Kozhikode         Wayanad          Kannur        Kasaragod      
##  Min.   :     0   Min.   :  192   Min.   :    0   Min.   :    0.0  
##  1st Qu.:  1259   1st Qu.: 1888   1st Qu.: 1308   1st Qu.:  386.2  
##  Median :  2442   Median : 5306   Median : 3802   Median : 2481.0  
##  Mean   : 11828   Mean   : 9731   Mean   :12630   Mean   : 8815.3  
##  3rd Qu.:  8818   3rd Qu.:10790   3rd Qu.: 8760   3rd Qu.: 4593.5  
##  Max.   :120683   Max.   :67414   Max.   :89238   Max.   :64335.0  
##  NA's   :1                        NA's   :1       NA's   :1

BAR PLOT MULTIPLE OPTIONS

randomcolor=grDevices::colors()[grep('gr(ale)y',grDevices::colors(),invert = T)]
barplot(data$Kollam,names=data$Crop,las=2,col = sample(randomcolor,length(data$Malappuram)),
        ylab="Area in Hectares",col.lab='olivedrab',cex.lab=0.9,
        lwd=1,col.axis=4,cex.axis = 0.8,font.lab=3,family="Gill Sans",
        main = "AREA UNDER CROPS IN 2017-18",cex.main=1.1,col.main=10,font.main=4,
        ylim=c(0,60000),font.axis=3)

mtext(side=1,line=4,"Crop name",col='orchid3',font=3,cex=0.8,family='Arial Narrow')

HISTOGRAM WITH DIFFERENT OPTIONS

area=read.csv("/Users/shibukumarapple/Desktop/Paddy_A.csv")
print(area)
##       Year Kerala_A1000 Kerala_A India_A Perc
## 1  1955-56       759353    75.94    3152 2.41
## 2  1956-57       781398    78.14    3228 2.42
## 3  1957-58       766774    76.68    3230 2.37
## 4  1958-59       768435    76.84    3317 2.32
## 5  1959-60       768966    76.90    3382 2.27
## 6  1960-61       778926    77.89    3413 2.28
## 7  1961-62       752704    75.27    3469 2.17
## 8  1962-63       802676    80.27    3569 2.25
## 9  1963-64       805083    80.51    3581 2.25
## 10 1964-65       801121    80.11    3646 2.20
## 11 1965-66       802329    80.23    3547 2.26
## 12 1966-67       799438    79.94    3525 2.27
## 13 1967-68       809544    80.95    3644 2.22
## 14 1968-69       873871    87.39    3697 2.36
## 15 1969-70       874059    87.41    3768 2.32
## 16 1970-71       874830    87.48    3759 2.33
## 17 1971-72       875157    87.52    3776 2.32
## 18 1972-73       873704    87.37    3669 2.38
## 19 1973-74       874675    87.47    3829 2.28
## 20 1974-75       881466    88.15    3948 2.23
## 21 1975-76       876022    87.60    3948 2.22
## 22 1976-77       854374    85.44    3851 2.22
## 23 1977-78       840374    84.04    4028 2.09
## 24 1978-79       799238    79.92    4048 1.97
## 25 1979-80       793266    79.33    3942 2.01
## 26 1980-81       801699    80.17    4015 2.00
## 27 1981-82       806871    80.69    4071 1.98
## 28 1982-83       778499    77.85    3826 2.03
## 29 1983-84       740086    74.01    4124 1.79
## 30 1984-85       730379    73.04    4116 1.77
## 31 1985-86       678281    67.83    4114 1.65
## 32 1986-87       663803    66.38    4117 1.61
## 33 1987-88       604082    60.41    3881 1.56
## 34 1988-89       577557    57.76    4173 1.38
## 35 1989-90       583388    58.34    4217 1.38
## 36 1990-91       559450    55.95    4269 1.31
## 37 1991-92       541327    54.13    4265 1.27
## 38 1992-93       537608    53.76    4178 1.29
## 39 1993-94       507832    50.78    4254 1.19
## 40 1994-95       503290    50.33    4281 1.18
## 41 1995-96       471150    47.12    4284 1.10
## 42 1996-97       430826    43.08    4343 0.99
## 43 1997-98       387122    38.71    4345 0.89
## 44 1998-99       352631    35.26    4480 0.79
## 45 1999-00       349774    34.98    4516 0.77
## 46 2000-01       347455    34.75    4471 0.78
## 47 2001-02       322368    32.24    4490 0.72
## 48 2002-03       310521    31.05    4118 0.75
## 49 2003-04       287340    28.73    4259 0.67
## 50 2004-05       289974    29.00    4191 0.69
## 51 2005-06       275742    27.57    4366 0.63
## 52 2006-07       263529    26.35    4381 0.60
## 53 2007-08       228938    22.89    4391 0.52
## 54 2008-09       234265    23.43    4554 0.51
## 55 2009-10       234013    23.40    4192 0.56
## 56 2010-11       213187    21.32    4286 0.50
## 57 2011-12       208161    20.82    4401 0.47
## 58 2012-13       197277    19.73    4275 0.46
## 59 2013-14       199611    19.96    4395 0.45

Histogram

hist(area$India_A,breaks = 10,col=(sample(randomcolor)),border = 34,freq = FALSE,
     main="HISTOGRAM OF AREA UNDER PADDY IN INDIA FROM 1956 TO 2014",
     cex.main=1,col.main='darkviolet',xlab='Area under Paddy',
     col.lab=2,cex.lab=0.8,font.lab=2,font.axis=3,col.axis=4,lwd=2)
# add a normal distribution line in histogram
curve(dnorm(x, mean=mean(area$India_A), sd=sd(area$India_A)), add=TRUE, col="green") 

HISTOGRAM WITH FREQUENCY COUNTS

h=hist(area$India_A,breaks = 10,col=(sample(randomcolor)),border = 34,freq = TRUE,
     main="HISTOGRAM OF AREA UNDER PADDY IN INDIA FROM 1956 TO 2014",
     cex.main=1,col.main='darkviolet',xlab='Area under Paddy',
     col.lab=2,cex.lab=0.8,font.lab=2,font.axis=3,col.axis=4,lwd=2)
h
## $breaks
## [1] 3000 3200 3400 3600 3800 4000 4200 4400 4600
## 
## $counts
## [1]  1  4  6  7  7 13 15  6
## 
## $density
## [1] 8.474576e-05 3.389831e-04 5.084746e-04 5.932203e-04 5.932203e-04
## [6] 1.101695e-03 1.271186e-03 5.084746e-04
## 
## $mids
## [1] 3100 3300 3500 3700 3900 4100 4300 4500
## 
## $xname
## [1] "area$India_A"
## 
## $equidist
## [1] TRUE
## 
## attr(,"class")
## [1] "histogram"
text(h$mids,h$counts,labels=h$counts, adj=c(0.5, -0.5),cex=1,font=4,col='deeppink')

HISTOGRAM WITH UNEQUAL BREAKS IN BARS

h=hist(area$India_A,col=(sample(randomcolor)),border = 5,freq = TRUE,
       main="HISTOGRAM OF AREA UNDER PADDY IN INDIA FROM 1956 TO 2014",
       cex.main=1,col.main='chocolate',xlab='Area under Paddy',
       col.lab=2,cex.lab=0.8,font.lab=2,font.axis=3,col.axis=4,lwd=2,
       breaks=c(3000,3400,4000,4400,4500,5000))
## Warning in plot.histogram(r, freq = freq1, col = col, border = border,
## angle = angle, : the AREAS in the plot are wrong -- rather use 'freq =
## FALSE'
h
## $breaks
## [1] 3000 3400 4000 4400 4500 5000
## 
## $counts
## [1]  5 20 28  4  2
## 
## $density
## [1] 2.118644e-04 5.649718e-04 1.186441e-03 6.779661e-04 6.779661e-05
## 
## $mids
## [1] 3200 3700 4200 4450 4750
## 
## $xname
## [1] "area$India_A"
## 
## $equidist
## [1] FALSE
## 
## attr(,"class")
## [1] "histogram"
text(h$mids,h$counts,labels=h$counts, adj=c(0.5, -0.5),cex=0.8,font=4,col='steelblue')

STUDY THE RELATION BETWEEN TWO VARIABLES

data=read.csv("/Volumes/Apple/Programming/R_DataFiles/RD/Plantain_Agri.csv")
print(data)
##       Year  Area Production Productivity
## 1  2004-05 54612     416115         7619
## 2  2005-06 55222     445333         8064
## 3  2006-07 53096     435636         8205
## 4  2007-08 51367     391896         7629
## 5  2008-09 50126     399633         7973
## 6  2009-10 47802     338546         7082
## 7  2010-11 49129     353772         7201
## 8  2011-12 48747     330634         6783
## 9  2012-13 48859     351315         7190
## 10 2013-14 54512     362395         6648
x=data$Area
y=data$Production
print(x)
##  [1] 54612 55222 53096 51367 50126 47802 49129 48747 48859 54512
print(y)
##  [1] 416115 445333 435636 391896 399633 338546 353772 330634 351315 362395
plot(y~x)

Customised scatter diagram

par(mar=c(5,4,3,1))   # set the margin 
plot(y~x,xaxt="none",yaxt="none",xlab="",ylab="",col='deeppink',cex=1.5,pch=18)
axis(1,seq(46000,56000,1000),las=2,font=3,cex.axis=0.7,family='Optima',lwd=3,col.ticks = 'red')
axis(2,seq(330000,450000,10000),las=2,font=3,cex.axis=0.7,col='violet',col.axis='darkorange')
abline(h=seq(330000,450000,10000),v=seq(46000,56000,1000),lty=2,col='gray')
mtext(side=1,line=3,"Production of plantain",col='blue',font=2,cex=0.8,family='Arial Narrow')
mtext(side=2,line=3,'Area of plantain',col='darkgreen',font=2,cex=0.8,family='Arial Narrow')
mtext(side=3,line=0.5,'Area Vs Production of plantain- Scatter chart',col='red',cex=1.3,
      family='Palatino',font=4)
text(x=49000,y=435000,'Relation between area and production',col='gold3',font=3,cex=0.7)