Rows: 220 Columns: 6
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (3): prod_type, prod_process, source
dbl (2): n_hens, n_eggs
date (1): observed_month
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#### Fazendo com a Marinaggplot(sel, aes(x=Ano, y=n_hens, fill=prod_process))+geom_boxplot()+facet_wrap(~prod_process, scales ="free")
galinha<-ggplot(data=filter(sep, prod_process!="all"),aes(x=Ano, y=n_hens, fill=prod_process))+geom_boxplot()+facet_wrap(~prod_process, scales ="free_y")+labs(title ="Number of hens", subtitle ="Per million", tag ="(A)")+scale_fill_brewer(palette ="YlOrBr")+theme_classic()+theme(axis.title =element_blank(), plot.background =element_rect(fill ="#F0E9AD", color =NA), strip.background =element_rect(fill ="#FFED3D"), panel.background =element_rect(fill ="#FAEF8F", color ="black"), legend.position ="none")galinha
ovos<-ggplot(data=filter(sep, prod_process!="all"),aes(x=Ano, y=n_eggs/10000, fill=prod_process))+geom_boxplot()+facet_wrap(~prod_process, scales ="free_y")+labs(title ="Number of eggs", subtitle ="Per million", tag ="(B)")+scale_fill_brewer(palette ="YlOrBr")+theme_classic()+theme(axis.title =element_blank(), plot.background =element_rect(fill ="#F0E9AD", color =NA), strip.background =element_rect(fill ="#FFED3D"), panel.background =element_rect(fill ="#FAEF8F", color ="black"), legend.position ="none")ovos
# essas últimas linhas são para por nome em cada um dos boxplot no gráficolibrary(patchwork)# esse é um pacote para a composição de gráficospainel1<-galinha/ovos#um acima do outropainel1
painel2<-galinha+ovos#um do lado do outropainel2
#ggsave("opcao1.jpg", painel1, dpi = 200, units = "cm", width = 12, height = 12)#ggsave("opcao2.pdf", painel2, units = "cm", width = 24, height = 9)painel3<-galinha/ovos+plot_annotation(title ="Produção de ovos nos Estados Unidos 2016-2021", subtitle ="Aumento expressivo de galinhas criadas livres", caption ="Plot for @TudyTuesday | By Aline Fonseca", theme=theme(plot.background =element_rect(fill ="#B2A374", color =NA), plot.title =element_text(color ="#FFED3D")))painel3
Comparando a produtividade dos diferentes tipos de processos e dos diferentes tipos de produtos
razao<-sep%>%mutate(produtividade =(n_hens/n_eggs))# display.brewer.all()prod_process<-ggplot(razao, aes(x=prod_type, y=produtividade, fill=prod_type))+geom_boxplot()+scale_fill_manual(values =c("lightblue", "aquamarine"))+labs(x="Tipo de produção", y="Produtividade",title="Figura 2", subtitle ="Produtividade entre os diferentes processos")prod_process
# Fazendo com a Marina# install.packages("ggridges")library(ggridges)ggplot(razao, aes(x=produtividade, y=prod_process, fill =prod_type, color=prod_type))+geom_density_ridges(alpha=0.5)+scale_fill_manual(values =c("#F1EB17", "#F1172A"), labels=c("Ovos de mesa","Ovos Incubabos"))+scale_color_manual(values =c("#F1EB17", "#F1172A"))+scale_y_discrete(labels =c(`cage-free (organic)`="Orgânico", `cage-free (non-organic)`="Não orgânico", all="Todos"))+scale_x_continuous(expand =c(0,0))+labs(title="Produtividade(ovos/galinha)", subtitle ="Produção orgânica se equipara a produção não orgânica")+theme_ridges()+guides(color="none")+theme(axis.title =element_blank(), legend.title =element_blank(), legend.position =c(0,0.9), panel.background =element_rect(fill ="#F5E3C7"), plot.background =element_rect(fill ="#F5E3C7"), panel.grid.major =element_line(color="#FAA805"), linetype="dashed", legend.backgroud =element_rect(fill ="#F5E3C7"))
Warning: A numeric `legend.position` argument in `theme()` was deprecated in ggplot2
3.5.0.
ℹ Please use the `legend.position.inside` argument of `theme()` instead.
Picking joint bandwidth of 0.000483
Warning in plot_theme(plot): The `linetype` theme element is not defined in the
element hierarchy.
Warning in plot_theme(plot): The `legend.backgroud` theme element is not
defined in the element hierarchy.
Comparando a produtividade entre os meses dos anos
prod_meses<-ggplot(razao, aes(x=produtividade, fill =Mes))+geom_density(alpha=0.4)+scale_y_continuous(expand =c(0,0))+labs(title="Figura 3", subtitle ="Produtividade entre os meses dos anos")prod_meses
#### Fazendo com a Marinalibrary(ggsci)ax3<-ggplot(razao, aes(x=Mes, y=produtividade, fill=prod_type))+geom_boxplot(alpha=0.6, width=0.4)+facet_wrap(~prod_process, ncol =1, scale ="free_y")+theme_minimal()+scale_fill_uchicago()+labs(title="Produtividade (ovos/galinha)", subtitle ="Diminuição no mês de fevereiro", x="Mês", y="Produtividade (ovos/galinha)")+theme(legend.title =element_blank(), legend.position ="top", panel.background =element_rect(fill ="#E1DFDA"), color=NA, plot.background =element_rect(fill ="#E1DFDA"), color=NA)ax3
Warning in plot_theme(plot): The `color` theme element is not defined in the
element hierarchy.
Rows: 21 Columns: 15
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (4): species, scientificname, taxa, commonname
dbl (11): censustarget, unidentified, rodent, granivore, minhfl, meanhfl, ma...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
reg_roedor<-ggplot(etbilu, aes(x=meanhfl, y=meanwgt))+geom_smooth(method ="lm")+geom_point()+labs(x="Tamanho do pé", y="Peso",title="Regressão linear", subtitle ="Comparando a média do tamanho do pé e peso dos roedores")reg_roedor
`geom_smooth()` using formula = 'y ~ x'
#### Fazendo com a Marinasummary(lm(meanwgt~meanhfl, data =etbilu))
Call:
lm(formula = meanwgt ~ meanhfl, data = etbilu)
Residuals:
Min 1Q Median 3Q Max
-37.816 -13.513 -4.370 3.438 94.332
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -42.4744 18.0311 -2.356 0.0294 *
meanhfl 3.4505 0.7045 4.897 1e-04 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 27.16 on 19 degrees of freedom
Multiple R-squared: 0.558, Adjusted R-squared: 0.5347
F-statistic: 23.99 on 1 and 19 DF, p-value: 1e-04
# install.packages("png")library(png)rato<-readPNG("mouse.png")ratinho<-ggplot(etbilu, aes(x=meanhfl, y=meanwgt))+theme_bw()+geom_point(alpha=0.9, color="#ADE1EE", size=4)+geom_smooth(method ="lm", se=F, color="#ADE1EE")+geom_text(label=etbilu$scientificname, check_overlap =T, fontface="italic", size=3)+labs(x="Tamanho do pé (mm)", y="Peso corporal (g)", title ="Relação entre peso e tamanho do pé de roedores")+annotate("text", label =expression(paste(r^2, "=0,53, p-value < 0.001")),x=45, y=15)+xlim(5,55)+annotation_raster(rato, xmin =10, xmax =20, ymin =100, ymax =150)ratinho
`geom_smooth()` using formula = 'y ~ x'
Warning in is.na(x): is.na() aplicado a um objeto diferente de lista ou vetor
de tipo 'expression'
juv<-ggplot(sep1, aes(x=Genero, y=juvwgt, fill =Genero))+geom_boxplot()+scale_fill_manual(values =c("lightblue", "aquamarine","lightpink", "orange", "yellowgreen", "violet", "seagreen", "salmon", "peru"))+labs(x="Gênero", y="Juvenis",title="Figura 4", subtitle ="Peso médio entre os gêneros")+theme(axis.text.x =element_blank(), axis.ticks.x =element_blank())juv
Warning: Removed 3 rows containing non-finite outside the scale range
(`stat_boxplot()`).
Source Code
---title: "Execício 3"author: "Aline Fonseca"date: "10 Oct 2024"cap-location: bottomtitle-block-banner: trueformat: htmlcode-link: truecode-tools: truetheme: vaportoc: truetoc-title: Índiceeditor: visualeditor_options: chunk_output_type: console---# Exercício 3 - Visualização de dados - `Dplyr`## Carregando a tabela e carregando pacotes```{r}eggs <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2023/2023-04-11/egg-production.csv')library(tidyverse)library(ggsci)library(knitr)library(kableExtra)library(tinytex)library(ggplot2)library(dplyr)library(RColorBrewer)eggs_divide <-mutate(eggs, n_hens = n_hens)```## Evolução do número de ovos de galinhas criadas livres (orgânicas e não-orgânicas) ao longo dos anos```{r}sep <- eggs_divide %>%separate(observed_month, into =c("Ano", "Mes", "Dia"), sep ="-")sel <-filter(sep, prod_type !="hatching eggs", prod_process !="all")prod_ovos <-ggplot(sel, aes(x=n_eggs, y=n_hens))+geom_smooth(method ="lm")+geom_point(aes(color=Ano))prod_ovos``````{r}#### Fazendo com a Marinaggplot(sel, aes(x= Ano, y= n_hens, fill= prod_process))+geom_boxplot()+facet_wrap(~prod_process, scales ="free")galinha <-ggplot(data=filter(sep, prod_process!="all"),aes(x= Ano, y= n_hens, fill= prod_process))+geom_boxplot()+facet_wrap(~prod_process, scales ="free_y")+labs(title ="Number of hens", subtitle ="Per million", tag ="(A)")+scale_fill_brewer(palette ="YlOrBr")+theme_classic()+theme(axis.title =element_blank(), plot.background =element_rect(fill ="#F0E9AD", color =NA),strip.background =element_rect(fill ="#FFED3D"),panel.background =element_rect(fill ="#FAEF8F", color ="black"), legend.position ="none")galinhaovos <-ggplot(data=filter(sep, prod_process!="all"),aes(x= Ano, y= n_eggs/10000, fill= prod_process))+geom_boxplot()+facet_wrap(~prod_process, scales ="free_y")+labs(title ="Number of eggs", subtitle ="Per million", tag ="(B)")+scale_fill_brewer(palette ="YlOrBr")+theme_classic()+theme(axis.title =element_blank(), plot.background =element_rect(fill ="#F0E9AD", color =NA),strip.background =element_rect(fill ="#FFED3D"),panel.background =element_rect(fill ="#FAEF8F", color ="black"), legend.position ="none")ovos# essas últimas linhas são para por nome em cada um dos boxplot no gráficolibrary(patchwork)# esse é um pacote para a composição de gráficospainel1 <- galinha/ovos #um acima do outropainel1painel2 <- galinha+ovos #um do lado do outropainel2#ggsave("opcao1.jpg", painel1, dpi = 200, units = "cm", width = 12, height = 12)#ggsave("opcao2.pdf", painel2, units = "cm", width = 24, height = 9)painel3 <- galinha/ovos +plot_annotation(title ="Produção de ovos nos Estados Unidos 2016-2021", subtitle ="Aumento expressivo de galinhas criadas livres", caption ="Plot for @TudyTuesday | By Aline Fonseca", theme=theme(plot.background =element_rect(fill ="#B2A374", color =NA), plot.title =element_text(color ="#FFED3D")))painel3#ggsave("opcao3.jpg", painel3, dpi = 200, width = 20, height = 20, unit = "cm")```## Comparando a produtividade dos diferentes tipos de processos e dos diferentes tipos de produtos```{r}razao <- sep %>%mutate(produtividade = (n_hens/n_eggs))# display.brewer.all()prod_process <-ggplot(razao, aes(x=prod_type, y=produtividade, fill= prod_type))+geom_boxplot()+scale_fill_manual(values =c("lightblue", "aquamarine"))+labs(x="Tipo de produção", y="Produtividade",title="Figura 2",subtitle ="Produtividade entre os diferentes processos")prod_process# Fazendo com a Marina# install.packages("ggridges")library(ggridges)ggplot(razao, aes(x= produtividade, y= prod_process, fill = prod_type, color= prod_type))+geom_density_ridges(alpha=0.5)+scale_fill_manual(values =c("#F1EB17", "#F1172A"),labels=c("Ovos de mesa","Ovos Incubabos"))+scale_color_manual(values =c("#F1EB17", "#F1172A"))+scale_y_discrete(labels =c(`cage-free (organic)`="Orgânico", `cage-free (non-organic)`="Não orgânico", all="Todos"))+scale_x_continuous(expand =c(0,0))+labs(title="Produtividade(ovos/galinha)", subtitle ="Produção orgânica se equipara a produção não orgânica")+theme_ridges()+guides(color="none")+theme(axis.title =element_blank(), legend.title =element_blank(),legend.position =c(0,0.9),panel.background =element_rect(fill ="#F5E3C7"),plot.background =element_rect(fill ="#F5E3C7"),panel.grid.major =element_line(color="#FAA805"),linetype="dashed", legend.backgroud =element_rect(fill ="#F5E3C7"))```## Comparando a produtividade entre os meses dos anos```{r}prod_meses <-ggplot(razao, aes(x=produtividade, fill = Mes))+geom_density(alpha=0.4)+scale_y_continuous(expand =c(0,0))+labs(title="Figura 3",subtitle ="Produtividade entre os meses dos anos") prod_meses#### Fazendo com a Marinalibrary(ggsci)ax3 <-ggplot(razao, aes(x= Mes, y= produtividade, fill= prod_type))+geom_boxplot(alpha=0.6, width=0.4)+facet_wrap(~prod_process, ncol =1, scale ="free_y")+theme_minimal()+scale_fill_uchicago()+labs(title="Produtividade (ovos/galinha)",subtitle ="Diminuição no mês de fevereiro",x="Mês", y="Produtividade (ovos/galinha)")+theme(legend.title =element_blank(), legend.position ="top",panel.background =element_rect(fill ="#E1DFDA"), color=NA,plot.background =element_rect(fill ="#E1DFDA"), color=NA)ax3#ggsave("exerc3.jpg", ax3, dpi = 200, width = 12, height = 16, unit= "cm")```## Faça um gráfico mostrando a relação linear entre o tamanho do pé e o peso dos roedores```{r}etbilu <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2023/2023-05-02/species.csv')reg_roedor <-ggplot(etbilu, aes(x=meanhfl, y=meanwgt))+geom_smooth(method ="lm")+geom_point()+labs(x="Tamanho do pé", y="Peso",title="Regressão linear",subtitle ="Comparando a média do tamanho do pé e peso dos roedores")reg_roedor#### Fazendo com a Marinasummary(lm(meanwgt~meanhfl, data = etbilu))# install.packages("png")library(png)rato <-readPNG("mouse.png")ratinho <-ggplot(etbilu, aes(x=meanhfl, y=meanwgt))+theme_bw()+geom_point(alpha=0.9, color="#ADE1EE", size=4)+geom_smooth(method ="lm", se=F, color="#ADE1EE")+geom_text(label= etbilu$scientificname, check_overlap = T, fontface="italic", size=3)+labs(x="Tamanho do pé (mm)", y="Peso corporal (g)",title ="Relação entre peso e tamanho do pé de roedores")+annotate("text", label =expression(paste(r^2, "=0,53, p-value < 0.001")),x=45, y=15)+xlim(5,55)+annotation_raster(rato, xmin =10, xmax =20, ymin =100, ymax =150)ratinho # theme(panel.grid = element_blank(),# panel.background = element_blank(),# plot.background = element_rect(color = NA)) # ggsave("ratinhofofinho.pdf", ratinho)```## Compare o peso médio e o peso dos juvenis entre os diferentes gêneros```{r}sep1 <- etbilu %>%separate(scientificname, into =c("Genero", "epiteto"), sep =" ")colours()juv <-ggplot(sep1, aes(x= Genero, y= juvwgt, fill = Genero))+geom_boxplot()+scale_fill_manual(values =c("lightblue", "aquamarine","lightpink", "orange", "yellowgreen", "violet", "seagreen", "salmon", "peru"))+labs(x="Gênero", y="Juvenis",title="Figura 4",subtitle ="Peso médio entre os gêneros")+theme(axis.text.x =element_blank(), axis.ticks.x =element_blank()) juv ```