Utilizando os dados de produção de ovos nos EUA faça um gráfico mostrando a evolução do número de ovos de galinhas criadas livres (orgânicas e não-orgânicas) ao longo dos anos.
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.
ggsave("Grafico.jpg", Grafico1, units ="cm", width =20, height =15)ggsave("Grafico1.jpg", Grafico2, units ="cm", width =20, height =15)
Exercício 2
Utilizando os dados de produção de ovos nos EUA faça um gráfico comparando a produtividade dos diferentes tipos de processos e dos diferentes tipos de produtos.
eggproduction Use os dados de eggproduction readr::read_csv(‘https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2023/2023-04-11/egg-production.csv’)
Calcule a produtividade como a razão entre o número de galinhas e o número de ovos
echo =FALSElibrary(ggridges)
Warning: pacote 'ggridges' foi compilado no R versão 4.4.1
densidade <-ggplot(eggproduction, aes(x=Produtividade, y=prod_process, fill=prod_type)) +geom_density_ridges(alpha=0.5) +scale_fill_manual(values=c("#F1EB17", "#F1172A"),labels=c("Ovos Incubados","Ovos de Mesa")) +scale_y_discrete(expand =c(0,0),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() +theme(axis.title =element_blank(),legend.title =element_blank(),legend.position =c(0.2,0.85),panel.background =element_rect(fill ="#F0E9AD"),plot.background =element_rect(fill ="#F5E5C7"),panel.grid.major =element_blank(),legend.background =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.
print(densidade)
Picking joint bandwidth of 0.242
Exercício 3
Utilizando os dados de produção de ovos nos EUA faça um gráfico comparando a produtividade entre os meses dos anos.
eggproduction Use os dados de eggproduction readr::read_csv(‘https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2023/2023-04-11/egg-production.csv’)
Calcule a produtividade como a razão entre o número de galinhas e o número de ovos
Veja a diferença entre os diferentes processos ou tipos de produtos!
echo =FALSElibrary(tidyverse)library(ggsci)
Warning: pacote 'ggsci' foi compilado no R versão 4.4.1
eggproduction <- eggproduction %>%mutate(Produtividade = n_eggs / n_hens)exercicio3 <-ggplot(eggproduction, aes(x = month, y = Produtividade, fill = prod_type)) +geom_boxplot(alpha =0.6, width =0.4) +facet_wrap(~prod_process, ncol =1) +theme_classic() +scale_fill_uchicago() +labs(title ="Produtividade (ovos/galinha)",subtitle ="Diminuição no mês de fevereiro",x ="Month", y ="Productivity" ) +theme(legend.title =element_blank(), legend.position ="bottom", )print(exercicio3)
Exercício 4
Utilizando os dados do projeto portal - que não é do ET Bilu faça um gráfico mostrando a relação linear entre o tamanho do pé e o peso dos roedores.
portal project Use os dados de espécies readr::read_csv(‘https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2023/2023-05-02/species.csv’)
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.
ratinhofeliz <- png::readPNG("C:/Users/Lenovo/OneDrive - ufpr.br/Área de Trabalho/DOC_Ecologia/Visualização_R/Aulas/ratinhofeliz.png") ratinho_raster <-as.raster(ratinhofeliz)Exercicio4 <-ggplot(species, aes(x=meanhfl, y=meanwgt)) +geom_point(alpha=0.9, color="#ADE1EE", size=4) +geom_smooth(method ="lm", se=F, color="#ADE1EE") +geom_text(label=species$scientificname, check_overlap =TRUE, 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(ratinho_raster, xmin =10, xmax =20,ymin =100, ymax =150) +theme_classic()print(Exercicio4)
`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'
Exercício 5
#Utilizando os dados do projeto portal compare o peso médio e o peso dos juvenis entre os diferentes gêneros.
#portal project #Use os dados de espécies readr::read_csv(‘https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2023/2023-05-02/species.csv’)
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.
plotar <-ggplot(resultados_long, aes(x = Gênero, y = peso_medio, fill = tipo_peso)) +geom_bar(stat ="identity", position ="dodge") +labs(title ="Comparação do Peso Médio Geral e dos Juvenis por Gênero",x ="Gênero",y ="Peso Médio",fill ="Tipo de Peso") +theme_classic() +scale_fill_manual(values =c("#CD5C5C", "#FFA07A")) +theme(legend.title =element_blank(),legend.position ="bottom",panel.background =element_rect(fill ="#fff1f3", color =NA),plot.background =element_rect(fill ="#999999", color =NA))ggsave("Exercicio5.jpg", plotar, units ="cm", width =20, height =15)
Warning: Removed 1 row containing missing values or values outside the scale range
(`geom_bar()`).
Exercício 6
#Utilizando os dados do projeto portal compare o peso dos animais nos diferentes tratamentos para os diferentes sexos.
#portal project #Use os dados de surveys readr::read_csv(‘https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2023/2023-05-02/surveys.csv’)
Rows: 28364 Columns: 22
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (14): treatment, species, sex, reprod, age, testes, vagina, pregnant, n...
dbl (7): month, day, year, plot, stake, hfl, wgt
date (1): censusdate
ℹ 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.
`summarise()` has grouped output by 'treatment'. You can override using the
`.groups` argument.
plot_boxplot <-ggplot(dados_filtrados, aes(x = treatment, y = wgt, fill = sex)) +geom_boxplot(outlier.shape =NA, position =position_dodge(width =0.75)) +labs(title ="Distribuição do Peso / Tratamento e Sexo",x ="Tratamento",y ="Peso",fill ="Sexo") +theme_classic() +scale_fill_manual(values =c("#FF5733", "#FFC300")) +theme(legend.position ="bottom")print(plot_boxplot)
ggsave("Grafico6.jpg", plot_boxplot, units ="cm", width =20, height =15)
Exercício 7
#Utilizando os dados do projeto portal faça um gráfico comparando a relação linear entre o tamanho do pé e o peso dos roedores para os diferentes tratamentos.
#portal project #Use os dados de surveys readr::read_csv(‘https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2023/2023-05-02/surveys.csv’)
Rows: 28364 Columns: 22
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (14): treatment, species, sex, reprod, age, testes, vagina, pregnant, n...
dbl (7): month, day, year, plot, stake, hfl, wgt
date (1): censusdate
ℹ 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.
dados_filtrados <- surveys %>%select(wgt, hfl, treatment) %>%filter(!is.na(wgt), !is.na(hfl))dados_filtrados <- dados_filtrados %>%mutate(faixa_hfl =cut(hfl, breaks =5))plot_box_faixas <-ggplot(dados_filtrados, aes(x = faixa_hfl, y = wgt, fill = treatment)) +geom_boxplot(outlier.shape =NA, position =position_dodge(width =0.75)) +labs(title ="Faixa de Tamanho do Pé e Tratamento",x ="Faixa de Tamanho do Pé",y ="Peso",fill ="Tratamento") +theme_classic() +scale_fill_manual(values =c("#96955f", "#c1be07", "#f2f050")) +theme(legend.position ="bottom")print(plot_box_faixas)
ggsave("Grafico7.jpg", plot_box_faixas, units ="cm", width =20, height =15)