https://github.com/omarbenites/cropdatape
Package cropdatape https://omarbenites.github.io/cropdatape/
https://github.com/omarbenites/cropdatape
agriculture agroinformatics crops database opendata peru potato quinoa rice sweet tomato unalm wheat
Last synced: 4 months ago
JSON representation
Package cropdatape https://omarbenites.github.io/cropdatape/
- Host: GitHub
- URL: https://github.com/omarbenites/cropdatape
- Owner: omarbenites
- License: other
- Created: 2017-01-04T19:18:59.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-12-04T04:13:57.000Z (over 7 years ago)
- Last Synced: 2025-10-22T05:16:05.100Z (9 months ago)
- Topics: agriculture, agroinformatics, crops, database, opendata, peru, potato, quinoa, rice, sweet, tomato, unalm, wheat
- Language: R
- Homepage:
- Size: 1.91 MB
- Stars: 0
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
```
# cropdatape
`cropdatape` provides peruvian agricultural production data from the Agriculture Minestry of Peru (MINAGRI). The first version includes 6 crops: rice, quinoa, potato, sweet potato, tomato and wheat; all of them across 24 departments. Initially, in excel files which has been transformed and assembled using tidy data principles, i.e. each variable is in a column, each observation is a row and each value is in a cell. The variables variables are sowing and harvest area per crop, yield, production and price per plot, every one year, from 2004 to 2014.
## Installation
You can install `cropdatape` directly from `CRAN`:
```{r, eval=FALSE}
install.packages("cropdatape")
```
Or, you can install from `GitHub`:
```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("omarbenites/cropdatape")
```
The `cropdatape` data frame include 9 variables,
| variable | meaning | units |
|:------------|:-------------------------|----------|
| crop | crop | - |
| department | deparment or region | - |
| year | year | - |
| month | month | - |
| sowa | sowing area | ha |
| harva | harvested area | ha |
| production | production | t |
| yield | yield | kg/ha |
| pricePlot | price per plot | s/kg |
### Usage
#### Example 1: Filter, grouped and summarize cropdatape data
In this example, we will explore the cropdatape dataset, using three (dplyr) functionlities: `filter`, `group` and `summarize`.
1. `filter` crop by `sweet potato`.
2. `group_by` department column.
3. `summarise` by mean of the sweetpotato yield.
`cropdatape` package:
```{r, message = FALSE, warning = FALSE}
#Load cropdatape package
library(cropdatape)
#Load dplyr package to filter and select information
library(dplyr)
cropdatape %>%
filter(crop == "sweet potato") %>%
group_by(department, year) %>%
summarise(yieldMean = mean(yield, na.rm = TRUE))
```
#### Example 2: Plot graphics with ggplot using cropdatape data
This second example we will explore the behaviour of the `yield` varible grouped by `crop`, from 2004 till 2014. The `crop` variable involves 6 crops: potato, quinoa, rice, sweet potato and wheat.
```{r example, echo=TRUE, warning=FALSE}
library(cropdatape)
library(ggplot2)
ggplot(cropdatape, aes(x = crop, y = yield)) +
geom_boxplot(outlier.colour = "hotpink") +
geom_jitter(position = position_jitter(width = 0.1, height = 0), alpha = 1/4)
```
#### Example 3: Animations with gganimate
To begin with, install the following packages from Github:
```{r,eval=FALSE}
#Install first devtools package
#install.packages("devtools")
library(devtools)
install_github("thomasp85/gganimate")
install_github("thomasp85/transformr")
install_github("thomasp85/tweenr")
```
Then, we will filter all the information related to sweetpotato
```{r, message=FALSE, warning=FALSE}
library(cropdatape)
library(dplyr)
sp <- cropdatape %>%
filter(crop == "quinoa", department == "Puno") %>%
group_by(department, year) %>%
summarise(sowaMean = mean(sowa,na.rm = TRUE),
harvaMean = mean(harva, na.rm = TRUE),
yieldMean = mean(yield, na.rm = TRUE))
```
Plotting and animating the scatter graph `years` vs `yieldMean`
```{r, cache=TRUE, warning=FALSE}
library(gganimate)
library(ggplot2)
library(transformr)
sp$year <- as.integer(sp$year)
yearlbl<- sp$year
ggplot(sp, aes(year, yieldMean)) +
geom_point(size= 1.5)+
scale_x_continuous(breaks = yearlbl)+
labs(title = 'Year: {frame_time}', x = 'Year', y = 'Yield') +
transition_time(year) +
ease_aes('linear')
```
Install and `emojifonts` package:
```{r, message=FALSE, warning=FALSE}
devtools::install_github("dill/emoGG")
library(emoGG)
```
Let the animation begins,
```{r, cache=TRUE, warning=FALSE}
library(gganimate)
library(ggplot2)
library(transformr)
sp$year <- as.integer(sp$year)
yearlbl<- sp$year
ggplot(sp, aes(year, yieldMean)) +
scale_x_continuous(breaks = yearlbl)+
geom_emoji(emoji="1f360")+
labs(title = 'Year: {frame_time}', x = 'Year', y = 'Yield') +
transition_time(year) +
ease_aes('linear')
```