Carregamento dos dados

library(knitr)
library(ggplot2)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ lubridate 1.9.3     ✔ tibble    3.2.1
## ✔ purrr     1.0.2     ✔ tidyr     1.3.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)
library(readxl)

MATRIX_R <- read_excel("MATRIX_R.xlsx")
MATRIX_R$SAMPLE_YEAR <- factor(MATRIX_R$SAMPLE_YEAR, ordered = T)
MATRIX_R$ID_DE <- factor(MATRIX_R$ID_DE, ordered = T)
str(MATRIX_R)
## tibble [1,477 × 11] (S3: tbl_df/tbl/data.frame)
##  $ SAMPLE_YEAR    : Ord.factor w/ 3 levels "2020"<"2021"<..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ ID_RA          : num [1:1477] 7 7 7 7 7 7 7 7 7 6 ...
##  $ REGION_AGRAR   : chr [1:1477] "Algarve" "Algarve" "Algarve" "Algarve" ...
##  $ ID_DE          : Ord.factor w/ 7 levels "0"<"1"<"2"<"3"<..: 7 2 3 4 1 2 3 4 5 6 ...
##  $ DE             : chr [1:1477] "≥ 1 000 000 €" "≥ 4 000 €  a < 25 000 €" "≥ 25 000 €  a < 50 000 €" "≥ 50 000 €  a < 100 000 €" ...
##  $ ID_OTE         : num [1:1477] 4 5 5 5 7 7 7 7 7 3 ...
##  $ TYPE_FARMING   : chr [1:1477] "Specialist  intensive horticulture" "Specialist quality wine" "Specialist quality wine" "Specialist quality wine" ...
##  $ OPTIMAL_SAMPLE : num [1:1477] 1 0 0 1 0 12 4 5 4 1 ...
##  $ REALISED_SAMPLE: num [1:1477] 0 1 0 0 1 5 16 28 29 0 ...
##  $ POPULATION     : num [1:1477] 13 18 11 6 0 ...
##  $ OTEP           : chr [1:1477] "Especialização Horticultura Intensiva" "Especialização Vinhos Qualidade" "Especialização Vinhos Qualidade" "Especialização Vinhos Qualidade" ...
MATRIX_R$ID_OTE <- factor(MATRIX_R$ID_OTE, ordered = T)
str(MATRIX_R)
## tibble [1,477 × 11] (S3: tbl_df/tbl/data.frame)
##  $ SAMPLE_YEAR    : Ord.factor w/ 3 levels "2020"<"2021"<..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ ID_RA          : num [1:1477] 7 7 7 7 7 7 7 7 7 6 ...
##  $ REGION_AGRAR   : chr [1:1477] "Algarve" "Algarve" "Algarve" "Algarve" ...
##  $ ID_DE          : Ord.factor w/ 7 levels "0"<"1"<"2"<"3"<..: 7 2 3 4 1 2 3 4 5 6 ...
##  $ DE             : chr [1:1477] "≥ 1 000 000 €" "≥ 4 000 €  a < 25 000 €" "≥ 25 000 €  a < 50 000 €" "≥ 50 000 €  a < 100 000 €" ...
##  $ ID_OTE         : Ord.factor w/ 18 levels "0"<"1"<"2"<"3"<..: 5 6 6 6 8 8 8 8 8 4 ...
##  $ TYPE_FARMING   : chr [1:1477] "Specialist  intensive horticulture" "Specialist quality wine" "Specialist quality wine" "Specialist quality wine" ...
##  $ OPTIMAL_SAMPLE : num [1:1477] 1 0 0 1 0 12 4 5 4 1 ...
##  $ REALISED_SAMPLE: num [1:1477] 0 1 0 0 1 5 16 28 29 0 ...
##  $ POPULATION     : num [1:1477] 13 18 11 6 0 ...
##  $ OTEP           : chr [1:1477] "Especialização Horticultura Intensiva" "Especialização Vinhos Qualidade" "Especialização Vinhos Qualidade" "Especialização Vinhos Qualidade" ...
summary(MATRIX_R)
##  SAMPLE_YEAR     ID_RA       REGION_AGRAR       ID_DE        DE           
##  2020:499    Min.   :1.000   Length:1477        0: 33   Length:1477       
##  2021:495    1st Qu.:2.000   Class :character   1:307   Class :character  
##  2022:483    Median :4.000   Mode  :character   2:297   Mode  :character  
##              Mean   :4.095                      3:298                     
##              3rd Qu.:6.000                      4:276                     
##              Max.   :7.000                      5:156                     
##                                                 6:110                     
##      ID_OTE    TYPE_FARMING       OPTIMAL_SAMPLE   REALISED_SAMPLE  
##  13     :112   Length:1477        Min.   : 0.000   Min.   :  0.000  
##  4      :111   Class :character   1st Qu.: 1.000   1st Qu.:  0.000  
##  7      :108   Mode  :character   Median : 2.000   Median :  1.000  
##  11     :108                      Mean   : 4.026   Mean   :  3.484  
##  15     :107                      3rd Qu.: 5.000   3rd Qu.:  3.000  
##  17     :104                      Max.   :48.000   Max.   :133.000  
##  (Other):827                                                        
##    POPULATION         OTEP          
##  Min.   :   0.0   Length:1477       
##  1st Qu.:  12.0   Class :character  
##  Median :  43.0   Mode  :character  
##  Mean   : 236.7                     
##  3rd Qu.: 190.0                     
##  Max.   :7256.0                     
## 
View(MATRIX_R)

Frequências por ANO/REGIÃO/DE/OTE (COMPARAÇÃO ENTE O RICA e o RA2019)

library(dplyr)
library(tidyr)
library (foreign)
library (survival)
library (MASS)
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
## 
##     select
library(nnet)
library (epiDisplay)
## 
## Attaching package: 'epiDisplay'
## The following object is masked from 'package:ggplot2':
## 
##     alpha
####  Frequências absolutas por ANO  da Amostra RICA

  YEAR_RICA_abs <- MATRIX_R %>%
  group_by(SAMPLE_YEAR) %>%
  summarise(Realisead_year_abs = sum(REALISED_SAMPLE),SAMPLE_YEAR)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'SAMPLE_YEAR'. You can override using the
## `.groups` argument.
  YEAR_RICA_abs   %>%
  ggplot(aes(x = "" , y = Realisead_year_abs , fill =SAMPLE_YEAR )) +
  geom_col(position = "dodge")+
labs(x = " ",
       y = "Nº farms",
       fill="Years",
       title = "Absolute frequency of farms by year  of the FADN sample" )
plot of chunk unnamed-chunk-2

#### Frequências relativas por ANO da Amostra RICA

YEARRICArel
<-
MATRIXR
%>%
groupby(SAMPLEYEAR)
%>%
summarise(Realiseadyearrel
=
sum(REALISEDSAMPLE)/5146*100,SAMPLE_YEAR)
## Warning:
Returning more (or less) than 1 row per summarise() group
was deprecated in

dplyr 1.1.0.

ℹ Please use reframe() instead.

ℹ When switching from summarise() to reframe(), remember that reframe()

always returns an ungrouped data frame and adjust accordingly.

Call lifecycle::last_lifecycle_warnings() to see where this warning was

generated.

## `summarise()` has grouped output by 'SAMPLE_YEAR'. You can override using the
## `.groups` argument.
##### geom_col


  YEAR_RICA_rel   %>%
  ggplot(aes(x = "" , y = Realisead_year_rel , fill =SAMPLE_YEAR )) +
  geom_col(position = "dodge")+
labs(x = " ",
       y = "Nº farms (%)",
       fill="Years",
       title = "Relative frequency of farms by year  of the FADN sample" )
plot of chunk unnamed-chunk-3
  ##### Boxplots 

RICA_boxplot  <- MATRIX_R %>%
      group_by(REGION_AGRAR,DE,ID_DE,TYPE_FARMING,ID_OTE, SAMPLE_YEAR) %>%
  summarise(Realisead_sample_Box= sum (REALISED_SAMPLE)/5146*100, REGION_AGRAR,DE,ID_OTE,TYPE_FARMING, SAMPLE_YEAR)
## `summarise()` has grouped output by 'REGION_AGRAR', 'DE', 'ID_DE',
## 'TYPE_FARMING', 'ID_OTE'. You can override using the `.groups` argument.
#### REGIÕES

ggplot(RICA_boxplot , aes(x = REGION_AGRAR, y =  Realisead_sample_Box, fill = SAMPLE_YEAR)) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Regions ",
       y = "Nº of farms (%)",
       fill= "Years",
       title = "Distributions of farms by region, type of farming and economic size of the FADN sample")
plot of chunk unnamed-chunk-3
 ####   DE

ggplot(RICA_boxplot , aes(x = ID_DE, y = Realisead_sample_Box , fill = SAMPLE_YEAR)) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Economic Size",
       y = " Nº of farms (%)",
       fill= "Years",
       title = "Distributions of farms by region, type of farming and economic size of the FADN sample")
plot of chunk unnamed-chunk-3
 ####   OTE

 ggplot(RICA_boxplot , aes(x = ID_OTE, y = Realisead_sample_Box , fill = SAMPLE_YEAR )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Type of farming",
       y = " Nº of farms (%)",
       fill= "Years",
       title = "Distributions of farms by region, type of farming and economic size of the FADN sample")
plot of chunk unnamed-chunk-3
   ####   OTE/DE
  ggplot(RICA_boxplot , aes(x = ID_OTE, y = Realisead_sample_Box , fill = DE )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Type of farming",
       y = " Nº of farms (%)",
       fill= "Economic Size Classes",
       title = "Distributions of farms by region, type of farming and economic size of the FADN sample")
plot of chunk unnamed-chunk-3
Frequências por Região da amostra RICA
### Frequências absolutas

RICA_REG_abs <- MATRIX_R %>%
  group_by(REGION_AGRAR) %>%
  summarise(Realisead_reg_abs = sum(REALISED_SAMPLE),REGION_AGRAR)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'REGION_AGRAR'. You can override using the
## `.groups` argument.
RICA_REG_abs  %>%
  ggplot(aes(x = "" , y = Realisead_reg_abs, fill = REGION_AGRAR )) +
  geom_col(position = "dodge")+
labs(x = " ",
       y = "Nº farms",
       fill="Regions",
       title = "Absolute frequency of farms by region of the FADN sample" )
plot of chunk unnamed-chunk-4
 ### Frequências relativas

RICA_REG_rel <- MATRIX_R %>%
  group_by(REGION_AGRAR) %>%
  summarise(Realisead_reg_rel = sum(REALISED_SAMPLE)/5146*100,REGION_AGRAR)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'REGION_AGRAR'. You can override using the
## `.groups` argument.
RICA_REG_rel  %>%
  ggplot(aes(x = "" , y = Realisead_reg_rel , fill = REGION_AGRAR )) +
  geom_col(position = "dodge")+
labs(x = " ",
       y = "Nº farms (%)",
       fill="Regions",
       title = "Relative frequency of farms by region of the FADN sample" )
plot of chunk unnamed-chunk-4
Frequências por Região do RA 2019
### Frequências absolutas 

RA2019_REG_abs <- MATRIX_R %>%
  group_by(REGION_AGRAR) %>%
  summarise(Population_reg_abs = sum (POPULATION),REGION_AGRAR)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'REGION_AGRAR'. You can override using the
## `.groups` argument.
RA2019_REG_abs   %>%
  ggplot(aes(x = "" , y = Population_reg_abs  , fill = REGION_AGRAR )) +
  geom_col(position = "dodge")+
labs(x = " ",
       y = "Nº farms",
       fill="Regions",
       title = "Absolute frequency of farms by region of RA2019" )
plot of chunk unnamed-chunk-5
 ### Frequências relativas

RICA_REG_rel <- MATRIX_R %>%
  group_by(REGION_AGRAR) %>%
  summarise(Population_reg_rel = sum(POPULATION)/349675*100,REGION_AGRAR)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'REGION_AGRAR'. You can override using the
## `.groups` argument.
RICA_REG_rel  %>%
  ggplot(aes(x = "" , y = Population_reg_rel , fill = REGION_AGRAR )) +
  geom_col(position = "dodge")+
labs(x = " ",
       y = "Nº farms (%)",
       fill="Regions",
       title = "Relative frequency of farms by region of the RA2019" )
plot of chunk unnamed-chunk-5

Frequências por Dimensão Economica da amostra RICA

######## Frequências absolutas por Dimensão Economica

RICA_DE_abs <- MATRIX_R %>%
  group_by(DE) %>%
  summarise(Real_realisead_abs = sum(REALISED_SAMPLE), DE)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'DE'. You can override using the `.groups`
## argument.
RICA_DE_abs %>%
  ggplot(aes(x = "", y = Real_realisead_abs, fill = DE )) +
  geom_col(position = "dodge")+
labs(x = "  ",
       y = "Nº of farms",
       fill="Economic size Class",
       title = " Absolute Frequencies of farms by economic size of the FADN sample" )
plot of chunk unnamed-chunk-6
######## Frequências relativas por Dimensão Economica


RICA_DE_rel <- MATRIX_R %>%
  group_by(DE) %>%
  summarise(Real_realisead_rel = sum(REALISED_SAMPLE)/5146*100, DE)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'DE'. You can override using the `.groups`
## argument.
RICA_DE_rel %>%
  ggplot(aes(x = "" , y =Real_realisead_rel, fill= DE )) +
  geom_col(position = "dodge")+
labs(x = " ",
       y = " Nº of farms (%)",
       fill= "Economic size class",
       title = "Relative Frequencies of farms by economic size of the FADN sample")
plot of chunk unnamed-chunk-6

Frequências por Dimensão Economica do RA 2019

######## Frequências absolutas por Dimensão Economica

RA2019_DE_abs  <- MATRIX_R %>%
  group_by(DE) %>%
  summarise(Population_DE_abs = sum (POPULATION),DE)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'DE'. You can override using the `.groups`
## argument.
RA2019_DE_abs %>%
  ggplot(aes( x = "", y = Population_DE_abs , fill = DE )) +
  geom_col(position = "dodge")+
labs(x = "",
       y = " Nº of farms",
       fill="Economic size class",
       title = "Absolute Frequencies of farms by economic size of the RA2019" )
plot of chunk unnamed-chunk-7
######## Frequências relativas por Dimensão Economica

RA2019_DE_rel  <- MATRIX_R %>%
  group_by(DE) %>%
  summarise(Population_DE_rel = sum (POPULATION)/349675*100, DE)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'DE'. You can override using the `.groups`
## argument.
RA2019_DE_rel  %>%
  ggplot(aes( x = "", y = Population_DE_rel, fill = DE )) +
  geom_col(position = "dodge")+
labs(x = "",
       y = " Nº of farms (%)",
       fill="Economic size class",
       title = "Relative Frequencies of farms by economic size of the RA2019" )
plot of chunk unnamed-chunk-7

Frequências por orientação técnico económica da amostra RICA

######## Frequências absolutas por orientação técnico económica

RICA_OTE_abs <- MATRIX_R %>%
  group_by(TYPE_FARMING) %>%
  summarise(Real_realisead_abs = sum(REALISED_SAMPLE), TYPE_FARMING)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'TYPE_FARMING'. You can override using the
## `.groups` argument.
RICA_OTE_abs %>%
  ggplot(aes(x = "", y = Real_realisead_abs, fill = TYPE_FARMING)) +
  geom_col(position = "dodge")+
labs(x = "  ",
       y = "Nº of farms",
       fill="Type of farming Class",
       title = " Absolute Frequencies of farms by Type of farming of the FADN sample" )
plot of chunk unnamed-chunk-8
######## Frequências relativas por orientação técnico económica


RICA_OTE_rel <- MATRIX_R %>%
  group_by(TYPE_FARMING) %>%
  summarise(Real_realisead_rel = sum(REALISED_SAMPLE)/5146*100, TYPE_FARMING)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'TYPE_FARMING'. You can override using the
## `.groups` argument.
RICA_OTE_rel %>%
  ggplot(aes(x = "" , y =Real_realisead_rel, fill= TYPE_FARMING)) +
  geom_col(position = "dodge")+
labs(x = " ",
       y = "Nº of farms (%)",
       fill= "Type of farming class",
       title = "Relative Frequencies of farms by Type of farming Class of the FADN sample")
plot of chunk unnamed-chunk-8

Frequências por Orientação orientação técnico económica do RA 2019

######## Frequências absolutas por orientação técnico económica

RA2019_OTE_abs  <- MATRIX_R %>%
  group_by(OTEP) %>%
  summarise(Population_OTE_abs = sum (POPULATION),TYPE_FARMING)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'OTEP'. You can override using the
## `.groups` argument.
RA2019_OTE_abs %>%
  ggplot(aes( x = "", y = Population_OTE_abs , fill = TYPE_FARMING )) +
  geom_col(position = "dodge")+
labs(x = "",
       y = " Nº of farms",
       fill="Type of farming class",
       title = "Absolute Frequencies of farms by Type of farming of the RA2019" )
plot of chunk unnamed-chunk-9
######## Frequências relativas por orientação técnico económica


RA2019_OTE_rel  <- MATRIX_R %>%
  group_by(TYPE_FARMING) %>%
  summarise(Population_OTE_rel = sum (POPULATION)/349675*100, TYPE_FARMING)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'TYPE_FARMING'. You can override using the
## `.groups` argument.
RA2019_OTE_rel  %>%
  ggplot(aes( x = "", y = Population_OTE_rel, fill = TYPE_FARMING )) +
  geom_col(position = "dodge")+
labs(x = "",
       y = " Nº of farms (%)",
       fill="Type of farming class",
       title = "Relative Frequencies of farms by economic size of the RA2019" )
plot of chunk unnamed-chunk-9
Boxplots RICA
######## RICA

  #### DISPERSÃO

 RICA_boxplot_DISP <- MATRIX_R %>%
  group_by(REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE) %>%
  summarise(Realisead_Sample = sum (REALISED_SAMPLE)/5146*100,REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'REGION_AGRAR', 'DE', 'ID_DE',
## 'TYPE_FARMING', 'ID_OTE'. You can override using the `.groups` argument.
  ggplot(RICA_boxplot_DISP, aes(x = DE, y = Realisead_Sample , fill = REGION_AGRAR )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Economic size classes",
       y = "Nº of farms (%)",
       fill= "Regions",
       title = "Distributions of farms by region, type of farming and economic size of the RICA 2020/2021/2022")
plot of chunk unnamed-chunk-10
   ggplot(RICA_boxplot_DISP, aes(x = Realisead_Sample, y =TYPE_FARMING , fill = REGION_AGRAR )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Type of farming",
       y = " Nº of farms (%)",
       fill= "Regions",
       title = "Distributions of farms by region, type of farming and economic size of the FADN sample")
plot of chunk unnamed-chunk-10
#### #### REGION/DE


#### DE= 1

RICA_boxplot_rel_1  <- MATRIX_R %>%
    filter(ID_DE==1) %>%
  group_by(REGION_AGRAR,ID_DE,TYPE_FARMING) %>%
  summarise(REALISED_SAMPLE_rel_1 = sum (REALISED_SAMPLE)/5146*100,REGION_AGRAR,DE,TYPE_FARMING)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'REGION_AGRAR', 'ID_DE', 'TYPE_FARMING'.
## You can override using the `.groups` argument.
ggplot(RICA_boxplot_rel_1 , aes(x = DE, y = REALISED_SAMPLE_rel_1, fill = REGION_AGRAR)) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Economic size class ",
       y = "Nº of farms by type of farming (%)",
       fill= "Regions",
       title = "Distributions of farms by type of farming, region and economic size class of the FADN sample")
plot of chunk unnamed-chunk-10
####### DE= 2,3,4,5,6


RICA_boxplot_rel_X  <- MATRIX_R %>%
    filter(ID_DE==2|ID_DE==3|ID_DE==4|ID_DE==5|ID_DE==6) %>%
  group_by(REGION_AGRAR,DE,ID_DE,TYPE_FARMING) %>%
  summarise(REALISED_SAMPLE_rel_X = sum (REALISED_SAMPLE)/5146*100,REGION_AGRAR,DE,TYPE_FARMING)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'REGION_AGRAR', 'DE', 'ID_DE',
## 'TYPE_FARMING'. You can override using the `.groups` argument.
ggplot(RICA_boxplot_rel_X  , aes(x = DE, y = REALISED_SAMPLE_rel_X, fill = REGION_AGRAR)) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Economic size class ",
       y = "Nº of farms by type of farming (%)",
       fill= "Regions",
       title = "Distributions of farms by Type of farming, region and economic size class of the FADN sample")
plot of chunk unnamed-chunk-10
#### REGION/OTE

  RICA_boxplot_OTE1234  <- MATRIX_R %>%
  filter(ID_OTE==1|ID_OTE==2|ID_OTE==3|ID_OTE==4) %>%
  group_by(REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE) %>%
  summarise(Realisead_sample_OTE = sum (REALISED_SAMPLE)/5146*100,REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'REGION_AGRAR', 'DE', 'ID_DE',
## 'TYPE_FARMING', 'ID_OTE'. You can override using the `.groups` argument.
 RICA_boxplot_OTE56789  <- MATRIX_R %>%
filter(ID_OTE==5|ID_OTE==6|ID_OTE==7|ID_OTE==8|ID_OTE==9) %>%
group_by(REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE) %>%
summarise(Realisead_sample_OTE = sum (REALISED_SAMPLE)/5146*100,REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'REGION_AGRAR', 'DE', 'ID_DE',
## 'TYPE_FARMING', 'ID_OTE'. You can override using the `.groups` argument.
 RICA_boxplot_OTE1011121314  <- MATRIX_R %>%
 filter(ID_OTE==10|ID_OTE==11|ID_OTE==12|ID_OTE==13|ID_OTE==14) %>%
  group_by(REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE) %>%
  summarise(Realisead_sample_OTE = sum (REALISED_SAMPLE)/5146*100,REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'REGION_AGRAR', 'DE', 'ID_DE',
## 'TYPE_FARMING', 'ID_OTE'. You can override using the `.groups` argument.
 RICA_boxplot_OTE151617 <- MATRIX_R %>%
 filter(ID_OTE==15|ID_OTE==16|ID_OTE==17) %>%
  group_by(REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE) %>%
  summarise(Realisead_sample_OTE = sum (REALISED_SAMPLE)/5146*100,REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'REGION_AGRAR', 'DE', 'ID_DE',
## 'TYPE_FARMING', 'ID_OTE'. You can override using the `.groups` argument.
  ggplot(RICA_boxplot_OTE1234 , aes(x = TYPE_FARMING, y = Realisead_sample_OTE , fill = REGION_AGRAR )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Type of farming",
       y = " Nº of farms (%)",
       fill= "Regions",
       title = "Distributions of farms by region, type of farming and economic size of the FADN sample")
plot of chunk unnamed-chunk-10
  ggplot(  RICA_boxplot_OTE56789 , aes(x = TYPE_FARMING, y = Realisead_sample_OTE , fill = REGION_AGRAR )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Type of farming",
       y = " Nº of farms (%)",
       fill= "Regions",
       title = "Distributions of farms by region, type of farming and economic size of theFADN sample")
plot of chunk unnamed-chunk-10
    ggplot( RICA_boxplot_OTE1011121314 , aes(x = TYPE_FARMING, y = Realisead_sample_OTE , fill = REGION_AGRAR )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Type of farming",
       y = " Nº of farms (%)",
       fill= "Regions",
       title = "Distributions of farms by region, type of farming and economic size of the FADN sample")
plot of chunk unnamed-chunk-10
      ggplot(RICA_boxplot_OTE151617, aes(x = TYPE_FARMING, y = Realisead_sample_OTE , fill = REGION_AGRAR )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Type of farming",
       y = " Nº of farms (%)",
       fill= "Regions",
       title = "Distributions of farms by region, type of farming and economic size of the FADN sample")
plot of chunk unnamed-chunk-10
####OTE/DE

   ggplot(RICA_boxplot_OTE1234 , aes(x = TYPE_FARMING, y = Realisead_sample_OTE , fill = DE )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Type of farming",
       y = " Nº of farms (%)",
       fill= "Economic size classes",
       title = "Distributions of farms by region, type of farming and economic size of the FADN sample")
plot of chunk unnamed-chunk-10
  ggplot( RICA_boxplot_OTE56789   , aes(x = TYPE_FARMING, y = Realisead_sample_OTE , fill = DE )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Type of farming",
       y = " Nº of farms (%)",
       fill= "Economic size classes",
       title = "Distributions of farms by region, type of farming and economic size of the FADN sample")
plot of chunk unnamed-chunk-10
    ggplot( RICA_boxplot_OTE1011121314  , aes(x = TYPE_FARMING, y = Realisead_sample_OTE , fill = DE )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Type of farming",
       y = " Nº of farms (%)",
       fill= "Economic size classes",
       title = "Distributions of farms by region, type of farming and economic size of the FADN sample")
plot of chunk unnamed-chunk-10
      ggplot( RICA_boxplot_OTE151617  , aes(x = TYPE_FARMING, y = Realisead_sample_OTE , fill = DE )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Type of farming",
       y = " Nº of farms (%)",
       fill= "Economic size classes",
       title = "Distributions of farms by region, type of farming and economic size of the FADN sample")
plot of chunk unnamed-chunk-10
Boxplots RA2019
#### REGION/OTE

  #### DISPERSÃO

 RA2019_boxplot_OTE_DISP <- MATRIX_R %>%
  group_by(REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE) %>%
  summarise(POPULATION_OTE = sum (POPULATION)/349675*100,REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'REGION_AGRAR', 'DE', 'ID_DE',
## 'TYPE_FARMING', 'ID_OTE'. You can override using the `.groups` argument.
  ggplot(RA2019_boxplot_OTE_DISP, aes(x = POPULATION_OTE , y =TYPE_FARMING , fill = REGION_AGRAR )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Type of farming",
       y = " Nº of farms (%)",
       fill= "Regions",
       title = "Distributions of farms by region, type of farming and economic size of the RA2019")
plot of chunk unnamed-chunk-11
   ggplot(RA2019_boxplot_OTE_DISP, aes(x = ID_DE, y = POPULATION_OTE , fill = REGION_AGRAR )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Type of farming",
       y = " Nº of farms (%)",
       fill= "Regions",
       title = "Distributions of farms by region, type of farming and economic size of the RA2019")
plot of chunk unnamed-chunk-11
 #### REGION/DE

RA2019_boxplot_DE1  <- MATRIX_R %>%
    filter(ID_DE==1) %>%
  group_by(REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE) %>%
  summarise(POPULATION_DE1 = sum (POPULATION)/349675*10,REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'REGION_AGRAR', 'DE', 'ID_DE',
## 'TYPE_FARMING', 'ID_OTE'. You can override using the `.groups` argument.
ggplot(RA2019_boxplot_DE1, aes(x = DE, y = POPULATION_DE1, fill = REGION_AGRAR )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Economic Size",
       y = " Nº of farms (%)",
       fill= "Regions",
       title = "Distributions of farms by region, type of farming and economic size of the RA2019")
plot of chunk unnamed-chunk-11
RA2019_boxplot_DEX  <- MATRIX_R %>%
    filter(ID_DE==2|ID_DE==3|ID_DE==4|ID_DE==5|ID_DE==6) %>%
  group_by(REGION_AGRAR,DE,ID_DE,TYPE_FARMING,ID_OTE) %>%
  summarise(POPULATION_DE_X =sum (POPULATION)/349675*100, REGION_AGRAR,DE,ID_DE,TYPE_FARMING,ID_OTE)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'REGION_AGRAR', 'DE', 'ID_DE',
## 'TYPE_FARMING', 'ID_OTE'. You can override using the `.groups` argument.
  ggplot(RA2019_boxplot_DEX , aes(x = DE, y = POPULATION_DE_X, fill = REGION_AGRAR )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Economic Size",
       y = " Nº of farms (%)",
       fill= "Regions",
       title = "Distributions of farms by region, type of farming and economic size of the RA2019")
plot of chunk unnamed-chunk-11
  #### REGION/OTE

  RA2019_boxplot_OTE1234  <- MATRIX_R %>%
  filter(ID_OTE==1|ID_OTE==2|ID_OTE==3|ID_OTE==4) %>%
  group_by(REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE) %>%
  summarise(POPULATION_OTE = sum (POPULATION)/349675*10,REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'REGION_AGRAR', 'DE', 'ID_DE',
## 'TYPE_FARMING', 'ID_OTE'. You can override using the `.groups` argument.
RA2019_boxplot_OTE56789  <- MATRIX_R %>%
filter(ID_OTE==5|ID_OTE==6|ID_OTE==7|ID_OTE==8|ID_OTE==9) %>%
group_by(REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE) %>%
summarise(POPULATION_OTE = sum(POPULATION)/349675*100,REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'REGION_AGRAR', 'DE', 'ID_DE',
## 'TYPE_FARMING', 'ID_OTE'. You can override using the `.groups` argument.
RA2019_boxplot_OTE1011121314  <- MATRIX_R %>%
 filter(ID_OTE==10|ID_OTE==11|ID_OTE==12|ID_OTE==13|ID_OTE==14) %>%
  group_by(REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE) %>%
  summarise(POPULATION_OTE = sum (POPULATION)/349675*100,REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'REGION_AGRAR', 'DE', 'ID_DE',
## 'TYPE_FARMING', 'ID_OTE'. You can override using the `.groups` argument.
 RA2019_boxplot_OTE151617  <- MATRIX_R %>%
 filter(ID_OTE==15|ID_OTE==16|ID_OTE==17) %>%
  group_by(REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE) %>%
  summarise(POPULATION_OTE = sum (POPULATION)/349675*100,REGION_AGRAR,DE,ID_DE,TYPE_FARMING, ID_OTE)
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `summarise()` has grouped output by 'REGION_AGRAR', 'DE', 'ID_DE',
## 'TYPE_FARMING', 'ID_OTE'. You can override using the `.groups` argument.
  ggplot(RA2019_boxplot_OTE1234 , aes(x = TYPE_FARMING, y = POPULATION_OTE , fill = REGION_AGRAR )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Type of farming",
       y = " Nº of farms (%)",
       fill= "Regions",
       title = "Distributions of farms by region, type of farming and economic size of the RA2019")
plot of chunk unnamed-chunk-11
  ggplot( RA2019_boxplot_OTE56789   , aes(x = TYPE_FARMING, y = POPULATION_OTE , fill = REGION_AGRAR )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Type of farming",
       y = " Nº of farms (%)",
       fill= "Regions",
       title = "Distributions of farms by region, type of farming and economic size of the RA2019")
plot of chunk unnamed-chunk-11
    ggplot( RA2019_boxplot_OTE1011121314  , aes(x = TYPE_FARMING, y = POPULATION_OTE , fill = REGION_AGRAR )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Type of farming",
       y = " Nº of farms (%)",
       fill= "Regions",
       title = "Distributions of farms by region, type of farming and economic size of the RA2019")
plot of chunk unnamed-chunk-11
      ggplot( RA2019_boxplot_OTE151617  , aes(x = TYPE_FARMING, y = POPULATION_OTE , fill = REGION_AGRAR )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Type of farming",
       y = " Nº of farms (%)",
       fill= "Regions",
       title = "Distributions of farms by region, type of farming and economic size of the RA2019")
plot of chunk unnamed-chunk-11
####OTE/DE

   ggplot(RA2019_boxplot_OTE1234 , aes(x = TYPE_FARMING, y = POPULATION_OTE , fill = DE )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Type of farming",
       y = " Nº of farms (%)",
       fill= "Economic size classes",
       title = "Distributions of farms by region, type of farming and economic size of the RA2019")
plot of chunk unnamed-chunk-11
  ggplot( RA2019_boxplot_OTE56789   , aes(x = TYPE_FARMING, y = POPULATION_OTE , fill = DE )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Type of farming",
       y = " Nº of farms (%)",
       fill= "Economic size classes",
       title = "Distributions of farms by region, type of farming and economic size of the RA2019")
plot of chunk unnamed-chunk-11
    ggplot( RA2019_boxplot_OTE1011121314  , aes(x = TYPE_FARMING, y = POPULATION_OTE , fill = DE )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Type of farming",
       y = " Nº of farms (%)",
       fill= "Economic size classes",
       title = "Distributions of farms by region, type of farming and economic size of the RA2019")
plot of chunk unnamed-chunk-11
      ggplot( RA2019_boxplot_OTE151617  , aes(x = TYPE_FARMING, y = POPULATION_OTE , fill = DE )) +
  stat_boxplot(geom = "errorbar", width = 0.25) +
  geom_boxplot() +
  labs(x = "Type of farming",
       y = " Nº of farms (%)",
       fill= "Economic size classes",
       title = "Distributions of farms by region, type of farming and economic size of the RA2019")
plot of chunk unnamed-chunk-11