-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlex dashboard _crop production.rmd
429 lines (318 loc) · 11.8 KB
/
Flex dashboard _crop production.rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
---
title: "India Crops"
output:
flexdashboard::flex_dashboard:
theme: united
logo: logo.jpg
orientation: rows
vertical_layout: scroll
social: [ "twitter", "facebook", "menu"]
source_code: embed
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(dplyr)
library(ggplot2)
library(plotly)
library(highcharter)
library(stringr)
library(RColorBrewer)
library(cowplot)
library(RCurl)
library(forcats)
library(viridis)
library(geojsonio)
library(reshape2)
```
```{r}
data <- read.csv("crop_production.csv",header=TRUE,stringsAsFactors = FALSE)
```
```{r}
data$Production <- round(data$Production/100,2)
data$Crop <- str_trim(data$Crop)
data$Season <- str_trim(data$Season)
```
```{r}
data$State_Name[data$State_Name == 'Andaman and Nicobar Islands']="Andaman and Nicobar"
data$State_Name[data$State_Name == 'Odisha']="Orissa"
data$State_Name[data$State_Name == 'Telangana']="Andhra Pradesh"
data$State_Name[data$State_Name == 'Uttarakhand']="Uttaranchal"
```
```{r}
xx <- data%>%
#filter(Crop == 'Coconut')%>%
filter(!is.na(Production) & Crop != 'Coconut')%>%
select(State_Name,Production)%>%
group_by(State_Name)%>%
summarise(total=sum(Production))
```
```{r}
xx_r <- xx %>%
mutate(label_text = str_glue("State:{State_Name} \n Quantity: {total} Quintal"))
```
<i class="fas fa-database"></i> Dataset
=============================================
Row
-------------------------------------------
### **Introduction:**
Agriculture is vital to any country, 60% of population works in the agriculture sector. In india comsumtion of Rice and Wheat is greater than the grops that are grown. Also main export is also Rice. This crops are also dependent on seasons. Each state has its own crop like kerala produces more coconuts. We are focusing more on Rice and Wheat as it is staple food in India.
**The aim of this project is to analyse the Crop production in Indian states and mainly rice and wheat production.**
### **Dataset Description:**
Columns | Description
--------------------------------|------------------------------------
State_Name | Name of thee state
District_Name | Name of the district
Crop_Year | Harvested year of the crop
Season | Season in which crop is harvested
Crop | Name of the crop
Area | Land area available for farming
Production | Amount of crop produced
Row
----------------------------------------
### **Dataset Details:**
* Dataset contains **246091 observations** and **7 columns**.
* India has total **33 States** and **646 Districts**.
* Total **126** different crops produced in **6 seasons**.
* Data is collected from **year 1997 till 2015**.
Row
----------------------------------------
### **Submited by:**
**Name:** Nithin Kumar Nukala
**College ID:** C00246450
<i class="far fa-chart-bar"></i> Visualization
=====================================
Row
-------------------------------------
### Total production in Quintal
```{r}
valueBox(sum(data$Production, na.rm = T),
icon = "glyphicon-leaf")
```
### Total States
```{r}
valueBox(length(unique(data$State_Name)),
icon = "fa-building",
color = "#58F8C6")
```
### Total Districts
```{r}
valueBox(length(unique(data$District_Name)),
icon = "glyphicon-home",
color = "#ECD036")
```
Column
-----------------------------------------------------------------------
### Crop Production till 2015 {data-commentary-width=400}
```{r}
plot1 <- ggplot(xx_r,aes(reorder(State_Name,total),total,fill = State_Name))+
geom_col(aes(text = label_text))+ coord_flip()+
scale_y_continuous(labels = scales::number_format())+
labs(y = "Crop production in Quintal",x = "States", title = "")+
theme(
legend.position="none",
panel.background = element_rect(fill = "white", colour = "turquoise3",size = 1.5, linetype = "solid"),
panel.grid.minor = element_line(size = .5, linetype = "blank" ),
panel.grid.major = element_line(size = .5, linetype = 'dotted',colour = "black"),
plot.title = element_text(face = "bold",colour = "mediumpurple4",size = 17)
)
ggplotly(plot1,tooltip = "text")
```
Row {.tabset .tabset-fade}
-------------------------------------
### Season-wise Rice Production
```{r}
a <- data%>%
filter(Crop == 'Rice')%>%
select(Season,Crop,Production)
ggplotly(ggplot(a,aes(x=Season, y = Production))+geom_boxplot(aes(fill = Season))+
theme(
legend.position="none",
panel.background = element_rect(fill = "white", colour = "turquoise3",size = 1.5, linetype = "solid"),
panel.grid.minor = element_line(size = .5, linetype = "blank" ),
panel.grid.major = element_line(size = .5, linetype = 'dotted',colour = "black"),
plot.title = element_text(face = "bold",colour = "mediumpurple4",size = 17)
))
```
### Area VS Production
```{r}
xc <- data%>%
filter(!is.na(Production) & State_Name != 'Kerala')%>%
select(State_Name,Area,Production)%>%
group_by(State_Name)%>%
summarise(area = round(mean(Area),2),
production = round(mean(Production),2))
melted <- melt(xc, id.var='State_Name', variable.name='type',
value.name='value')
```
```{r}
Plot5 <- ggplot(melted,aes(x = State_Name, y = value)) + geom_col(aes(fill=type),position = 'dodge')+
theme(axis.text.x = element_text(color="steel blue", angle=90),plot.title = element_text(face = "bold",colour = "#9E0142",size = 18))+ scale_y_continuous(labels = scales::number_format())+scale_fill_viridis(discrete=TRUE, guide=FALSE, option="D")+
theme(
axis.text.x=element_text(angle=45),legend.position="top",
panel.background = element_rect(fill = "white", colour = "turquoise3",size = 1.5, linetype = "solid"),
panel.grid.minor = element_line(size = .5, linetype = "dotted" ,colour = "black"),
panel.grid.major = element_line(size = .5, linetype = 'dotted',colour = "black"),
plot.title = element_text(face = "bold",colour = "mediumpurple4",size = 20)
)+
labs(
x = "",
y = "Value",
title = ""
)
ggplotly(Plot5)
```
Column
-----------------------------------------------------------------------
### Top States Producing Rice
```{r}
col <- brewer.pal(n = 10, name = 'Spectral')
```
```{r}
Plot2 <- data %>%
filter(!is.na(Production) & Crop == 'Rice')%>%
group_by(State_Name) %>%
summarise(rice = sum(Production)) %>%
filter(rice>660000) %>%
plot_ly(labels = ~State_Name,
values = ~rice,
marker = list(colors = col)
) %>%
add_pie(hole = 0.2) %>%
layout(xaxis = list(zeroline = F,
showline = F,
showticklabels = F,
showgrid = F),
yaxis = list(zeroline = F,
showline = F,
showticklabels=F,
showgrid=F))
Plot2
```
### Top States producing Wheat
```{r}
Plot3 <- data %>%
filter(!is.na(Production) & Crop == 'Wheat')%>%
group_by(State_Name) %>%
summarise(rice = sum(Production)) %>%
filter(rice>117000) %>%
plot_ly(labels = ~State_Name,
values = ~rice,
marker = list(colors = col)
) %>%
add_pie(hole = 0.2) %>%
layout(xaxis = list(zeroline = F,
showline = F,
showticklabels = F,
showgrid = F),
yaxis = list(zeroline = F,
showline = F,
showticklabels=F,
showgrid=F))
Plot3
```
<i class="fas fa-globe-asia"></i> Map
========================================
row {data-height=850}
-------
### State-wise production in India
```{r}
IndGeoMap <- geojson_read( 'https://code.highcharts.com/mapdata/countries/in/custom/in-all-andaman-and-nicobar.geo.json')
```
```{r}
sname <- data %>%
#filter(State_Name != 'Kerala')%>%
group_by(State_Name) %>%
summarize(fullcrop = round(sum(Production,na.rm = T),2))
highchart() %>%
hc_title(text = "Crop production in india") %>%
hc_subtitle(text = "state wise production in Quintal") %>%
hc_add_series_map(IndGeoMap, sname,
name = "State_Name",
value = "fullcrop",
joinBy = c("woe.name", "State_Name")) %>%
hc_mapNavigation(enabled = T)
```
<i class="fas fa-pencil-ruler"></i> Interactive
========================================
Column {.sidebar}
-----------------------------------------------------------------------
```{r}
fil_crop <- data%>%
filter(!is.na(Production) )%>%
group_by(Crop)%>%
summarise(prod = sum(Production))%>%
arrange(desc(prod))%>%
head(12)%>%
select(Crop)
```
```{r}
checkboxGroupInput(inputId = "Crop_in",
label = "Choose the Crop",
choices = c(fil_crop[[1]]),
selected = c("Rice","Sugarcane"))
```
```{r}
sliderInput(inputId = "slider_input",
label = "Year",
min = min(data$Crop_Year),
max = max(data$Crop_Year),
value = c(2002,2008),
step = 1)
```
```{r}
radioButtons(inputId = "radio_input",
label = "Choose season",
choices = unique(data$Season),
selected = "Kharif")
```
Column {data-width=350}
-----------------------------------------------------------------------
### Year-wise production of Crops
```{r}
crop_selected <- reactive({
data %>%
filter(Crop %in% input$Crop_in) %>%
filter(Crop_Year %>% between(left = input$slider_input[1],right = input$slider_input[2]))%>%
filter(Season == input$radio_input)
})
```
```{r}
renderPlotly({
crop_line <- crop_selected() %>%
group_by(Crop_Year,Crop) %>%
summarise(totPro = sum(Production, na.rm = T)) %>%
ggplot(aes(Crop_Year,totPro))+
geom_line(aes(color = Crop ))+scale_y_continuous(labels = scales::number_format())+
geom_point(shape=18, size=2, color = "red")+
theme(
legend.position="top",
panel.background = element_rect(fill = "white", colour = "turquoise3",size = 1.5, linetype = "solid"),
panel.grid.minor = element_line(size = .5, linetype = "dotted" ,colour = "black"),
panel.grid.major = element_line(size = .5, linetype = 'dotted',colour = "black"),
plot.title = element_text(face = "bold",colour = "mediumpurple4",size = 20)
)+
labs(
x = "Year",
y = "Total Production",
title = ""
)
ggplotly(crop_line)
})
```
<i class="fas fa-clipboard-list"></i> Insights
=========================================
```{r}
data11 <- data%>%
select(Crop_Year,Production)%>%
group_by(Crop_Year)%>%
summarise(Production = round(sum(Production, na.rm = T),2))
mm <- round(mean(data11$Production),2)
```
**Conclusion:**
* Average crop produced over the years is **74303219**.
* Crops are produced more from **Uttar Pradesh** state.
* **Rice** is harvested through out the year but is produced more in **Kharif season**.
* **Andaman and Nicobar** produces more crop utilizing less area, where as **Punjab** produces very less crop having more area.
* **West Bengal** state tops in **Rice** production where as **Uttar Pradesh** tops in **Wheat** production.
This report was generated on `r format(Sys.Date(), format = "%B %d, %Y")`.