class: center, middle, inverse, title-slide # Introdução ao uso de dados geoespaciais no R
## 5 Visualização de dados ### Maurício H. Vancine
Milton C. Ribeiro ### UNESP - Rio Claro
Laboratório de Ecologia Espacial e Conservação (LEEC) ### 25/10/2021-05/11/2021 --- class: clear, center, middle background-image: url(img/plot_saurus.png) background-size: 800px background-position: 50% 50% --- background-image: url(img/package_ggplot2.png) background-size: 300px background-position: 85% 75% # 5 Visualização de dados ## Conteúdo 1. Contextualização 1. Pacotes para produção de gráficos 1. Gramática dos gráficos 1. Principal material de estudo 1. Principais tipos de gráficos 1. Histograma e Densidade 1. Gráfico de setores 1. Gráfico de barras 1. Gráfico de caixas 1. Gráfico de dispersão 1. Gráfico pareado 1. Combinando gráficos 1. Gráficos animados 1. Gráficos interativos 1. Gráficos usando interface [ggplot2](https://ggplot2.tidyverse.org/) --- # 5 Visualização de dados ## Script <br><br><br><br><br><br> ## .center[`05_script_intro_geoespacial_r.R`] --- # 1. Contextualização ## Descrição ### Melhor forma de **apresentar, sintetizar, discutir e interpretar** seus dados -- ### Necessário em quase todas as **análises estatísticas** -- ### Necessário em quase todas as **publicações**, trabalhos de consultoria, TCC, dissertação, tese, etc. -- ### Existem vários **tipos de gráficos** para representar os padrões em seus dados para **diferentes tipos de finalidades** -- ### De forma simplificada, os gráficos são **representações** dos nossos dados tabulares --- # 2. Pacotes para produção de gráficos ### Principais pacotes -- #### [graphics](http://search.r-project.org/R/library/graphics/html/00Index.html): simples, porém útil para visualizações rápidas de quase todos os formatos de arquivos -- #### [ggplot2](https://ggplot2.tidyverse.org/): pacote integrado ao tidyverse, possui uma sintaxe própria baseada na gramática de gráficos por camadas (layers) -- #### [ggplot2 extentions](https://exts.ggplot2.tidyverse.org/): conjunto de pacotes que adicionam diversas expansões ao pacote ggplot2. Exemplos: [GGally](https://ggobi.github.io/ggally/), [gganimate](https://gganimate.com/) e [esquisse](https://dreamrs.github.io/esquisse/) -- #### [visdat](https://docs.ropensci.org/visdat/): cria visualizações preliminares de um conjunto de dados inteiro para identificar problemas ou recursos inesperados usando `ggplot2` -- #### [DataExplorer](http://boxuancui.github.io/DataExplorer/): automatiza a maior parte do manuseio e visualização de dados, para Análise Exploratória de Dados usando `ggplot2` -- #### [ggpubr](https://rpkgs.datanovia.com/ggpubr/): fornece algumas funções simplificadas para criar gráficos para publicação, baseados no `ggplot2` -- #### [cowplot]((https://wilkelab.org/cowplot/): pacote que permite combinar vários gráficos de forma elaborada -- #### [pacthwork](https://patchwork.data-imaginist.com/): pacote que permite combinar vários gráficos em um só de forma extremamente simples e com alta qualidade -- #### [plotly](https://plotly.com/r/): pacote para criar gráficos interativos da web por meio da biblioteca gráfica de JavaScript de código aberto plotly.js --- class: clear background-image: url(img/package_graphics.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [graphics](http://search.r-project.org/R/library/graphics/html/00Index.html) --- background-image: url(img/package_graphics.png) background-size: 250px background-position: 85% 85% # 2. Principais pacotes para gráficos ## **graphics** ### Default do R e mais simples -- ### Pode ser utilizado para objetos de **diversas classes** -- ### Possui funções como: `plot()`<br> `hist()`<br> `barplot()`<br> `boxplot()`<br> `abline()`<br> `points()`<br> `lines()`<br> `polygon()`<br> --- # 2. Principais pacotes para gráficos ## **graphics** ```r # graphics plot(flipper_length_mm ~ body_mass_g, data = penguins) ``` <img src="05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-1-1.png" width="35%" style="display: block; margin: auto;" /> --- class: clear background-image: url(img/package_ggplot2.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [ggplot2](https://ggplot2.tidyverse.org/) --- background-image: url(img/cheatsheet_ggplot2.png) background-size: 600px background-position: 50% 50% # 2. Principais pacotes para gráficos ## Data Visualization Cheatsheet <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [Data Visualization with ggplot2 Cheatsheet](https://github.com/rstudio/cheatsheets/raw/master/data-visualization-2.1.pdf) --- background-image: url(img/package_ggplot2.png) background-size: 250px background-position: 85% 85% # 2. Principais pacotes para gráficos ## **ggplot2** ### Integrado ao tidyverse, possui uma sintaxe própria -- ### Necessita de funções específicas para objetos de **classes diferentes** -- ### Estruturado dessa forma: `ggplot() +`<br> `aes() +`<br> `geom_() +`<br> `facet_() +`<br> `stats_() +`<br> `coord_() +`<br> `theme_()`<br> --- # 2. Principais pacotes para gráficos ## **ggplot2** ```r # ggplot2 library(ggplot2) ggplot(data = penguins) + aes(x = body_mass_g, y = flipper_length_mm) + geom_point() ``` <img src="05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-2-1.png" width="35%" style="display: block; margin: auto;" /> --- class: clear background-image: url(img/package_ggpubr.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [ggpubr](https://rpkgs.datanovia.com/ggpubr/) --- background-image: url(img/package_ggpubr.png) background-size: 250px background-position: 85% 85% # 2. Principais pacotes para gráficos ## **ggpubr** ### Funções fáceis de usar para criar e personalizar plots para publicações baseadas no "ggplot2" -- ### Necessita de funções específicas para gerar **gráficos específicos** -- ### Funções: `gghistogram()`<br> `ggdensity()`<br> `ggboxplot()`<br> `ggviolin()`<br> `ggbarplot()`<br> `ggscatter()`<br> --- # 2. Principais pacotes para gráficos ## **ggpubr** ```r # ggpubr library(ggpubr) ggscatter(penguins, x = "body_mass_g", y = "flipper_length_mm") ``` <img src="05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-3-1.png" width="35%" style="display: block; margin: auto;" /> --- background-image: url(img/cover_grammar_graphics.jpg), url(img/ggplot2_structure.png) background-size: 200px, 600px background-position: 20% 70%, 85% 70% # 3. Gramática dos gráficos ## Descrição ### Wilkinson (2005) *Grammar of Graphics*: representação gráfica dos dados a partir de atributos estéticos (do inglês *aesthetic*) <br><br><br><br><br><br><br><br><br><br><br><br> [Wilkinson (2005)](https://www.springer.com/gp/book/9780387245447) --- background-image: url(img/plot_ggplot.gif) background-size: 750px background-position: 50% 45% # 3. Gramática dos gráficos ## Descrição <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [Think About the Grammar of Graphics When Improving Your Graphs](https://medium.com/tdebeus/think-about-the-grammar-of-graphics-when-improving-your-graphs-18e3744d8d18) --- background-image: url(img/plot_ggplot2.png), url(img/ggplot2_gramatica.png) background-size: 500px, 600px background-position: 5% 70%, 90% 70% # 3. Gramática dos gráficos ## Descrição ### Wickham (2008) criou o pacote **ggplot2**, onde “gg” representa a contração de Grammar of Graphics <br><br><br><br><br><br><br><br><br><br><br><br> [Wickham (2008)](https://ggplot2-book.org/) --- background-image: url(img/person_hadley_wickham.jpg) background-size: 500px background-position: 50% 70% # 4. Principal material de estudo ## Livros ### O idealizador e mantenedor do pacote **ggplot2** foi de novo o **Hadley Wickham** <br><br><br><br><br><br><br><br><br><br><br><br><br> [Hadley Wickham](http://hadley.nz/) --- background-image: url(img/cover_ggplot2.jpg) background-size: 230px background-position: 50% 63% # 4. Principal material de estudo ## Livros ### ggplot2 (2009, 2016) <br><br><br><br><br><br><br><br><br><br><br><br><br> [Wickham (2009, 2016)](https://ggplot2.tidyverse.org/) --- background-image: url(img/cover_r_graphics_cookbook.jpg) background-size: 250px background-position: 50% 63% # 4. Principal material de estudo ## Livros ### R Graphics Cookbook (2018) <br><br><br><br><br><br><br><br><br><br><br><br><br> [Chang (2018)](http://www.cookbook-r.com/Graphs/) --- background-image: url(img/cover_data_science_r.png) background-size: 250px background-position: 50% 70% # 4. Principal material de estudo ## Livros ### R for Data Science (2017) <br><br><br><br><br><br><br><br><br><br><br><br><br> [Wickham & Grolemund (2017)](https://r4ds.had.co.nz/) --- background-image: url(img/cover_data_visualization_with_r.png) background-size: 230px background-position: 50% 65% # 4. Principal material de estudo ## Livros ### Data Visualization with R (2018) <br><br><br><br><br><br><br><br><br><br><br><br><br> [Kabacoff (2018)](https://rkabacoff.github.io/datavis/) --- background-image: url(img/cover_fundamentals_of_data_visualization.png) background-size: 260px background-position: 50% 63% # 4. Principal material de estudo ## Livros ### Fundamentals of Data Visualization (2019) <br><br><br><br><br><br><br><br><br><br><br><br><br> [Wilke (2019)](https://serialmentor.com/dataviz/) --- background-image: url(img/cover_interative.png) background-size: 260px background-position: 50% 68% # 4. Principal material de estudo ## Livros ### Interactive web-based data visualization with R, plotly, and shiny (2019) <br><br><br><br><br><br><br><br><br><br><br><br><br> [Sievert (2019)](https://plotly-r.com/) --- background-image: url(img/package_ggplot2.png) background-size: 300px background-position: 50% 60% # 4. Principal material de estudo ## Sites ### ggplot2: Reference <br><br><br><br><br><br><br><br><br><br><br><br><br> [ggplot2 reference](https://ggplot2.tidyverse.org/reference/) --- background-image: url(img/plot_r_graph_gallery.png) background-size: 800px background-position: 50% 60% # 4. Principal material de estudo ## Sites ### R Graph Gallery <br><br><br><br><br><br><br><br><br><br><br><br><br> [R Graph Gallery](https://www.r-graph-gallery.com/) --- background-image: url(img/plot_tree_s.png) background-size: 400px background-position: 50% 60% # 4. Principal material de estudo ## Sites ### from Data to Viz <br><br><br><br><br><br><br><br><br><br><br><br><br> [from Data to Viz](https://www.data-to-viz.com/) --- background-image: url(img/plot_sthda.png) background-size: 300px background-position: 50% 70% # 4. Principal material de estudo ## Sites ### Statistical tools for high-throughput data analysis (STHDA) <br><br><br><br><br><br><br><br><br><br><br><br><br> [STHDA](http://www.sthda.com/english/) --- class: inverse, center, middle # Dúvidas? --- class: inverse, center, middle # Os elementos de um gráfico são representações das colunas (eixos) e linhas (elementos) de nossas matrizes de dados --- background-image: url(img/plot_data_table_scatterplot.png) background-size: 800px background-position: 50% 70% # 5. Principais tipos de gráficos ## Colunas se tornam eixos e valores a representação --- background-image: url(img/plot_variables.png) background-size: 800px background-position: 50% 50% # 5. Principais tipos de gráficos ## Tipos de variáveis <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [Matthiopoulos (2011)](http://greenmaths.st-andrews.ac.uk/) --- background-image: url(img/nominal_ordinal_binary.png), url(img/continuous_discrete.png), url(img/plot_variables.png) background-size: 420px, 335px, 400px background-position: 23% 78%, 69% 78%, 50% 15% # 5. Principais tipos de gráficos ## Tipos de variáveis <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [Matthiopoulos (2011)](http://greenmaths.st-andrews.ac.uk/), [@allison_horst](https://twitter.com/allison_horst) --- class: inverse, center, middle # O **tipo e quantidade das variáveis** indicará o melhor tipo de gráfico para **representar** os dados --- background-image: url(img/ggplot_data_from_viz.png) background-size: 800px background-position: 50% 60% # 5. Principais tipos de gráficos ## from Data to Viz <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [from Data to Viz](https://www.data-to-viz.com/) --- class: inverse, center, middle # Dúvidas? --- class: inverse, center, middle # E que dados vamos usar? --- class: clear background-image: url(img/package_palmerpenguins.png) background-size: 400px <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [palmerpenguins](https://allisonhorst.github.io/palmerpenguins/) --- background-image: url(img/culmen_depth.png), url(img/lter_penguins.png) background-size: 400px, 400px background-position: 20% 85%, 80% 85% # palmerpenguins ## Dados de medidas de pinguins chamados `palmerpenguins` ```r # carregar library(palmerpenguins) # visualizar os dados penguins # glimpse tibble::glimpse(penguins) ``` <br><br><br><br><br><br><br><br> [palmerpenguins ](https://allisonhorst.github.io/palmerpenguins/) --- background-image: url(img/plot_histogram.png), url(img/plot_density.png) background-size: 300px, 300px background-position: 30% 80%, 70% 80% # 6. Histograma (*Histogram*) ### **Representa os dados de**: uma coluna ### **Tipo de dado**: discreto ou contínuo ### Distribuição de frequência e densidade de dados discretos ou contínuos --- class: clear background-image: url(img/package_graphics.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [graphics](http://search.r-project.org/R/library/graphics/html/00Index.html) --- # 6. Histograma (*Histogram*) ## graphics .pull-left[ ```r hist(penguins$flipper_length_mm) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-5-1.png)<!-- --> ] --- # 6. Histograma (*Histogram*) ## graphics .pull-left[ ```r hist(penguins$flipper_length_mm, col = "gray50", border = "gray") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-6-1.png)<!-- --> ] --- # 6. Histograma (*Histogram*) ## graphics .pull-left[ ```r hist(penguins$flipper_length_mm, col = "gray50", border = "gray", main = "Comprimento da nadadeira dos penguins") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-7-1.png)<!-- --> ] --- # 6. Histograma (*Histogram*) ## graphics .pull-left[ ```r hist(penguins$flipper_length_mm, col = "gray50", border = "gray", main = "Comprimento da nadadeira dos penguins", xlab = "Comprimento da nadadeira (mm)", ylab = "Frequência") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-8-1.png)<!-- --> ] --- # 6. Histograma (*Histogram*) ## graphics .pull-left[ ```r hist(penguins$flipper_length_mm, col = "gray50", border = "gray", main = "Comprimento da nadadeira dos penguins", xlab = "Comprimento da nadadeira (mm)", ylab = "Frequência", br = 50) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-9-1.png)<!-- --> ] --- # 6. Histograma (*Histogram*) ## graphics .pull-left[ ```r par(mar = c(5, 5, 5, 5)) hist(penguins$flipper_length_mm, col = "gray50", border = "gray", main = "Comprimento da nadadeira dos penguins", xlab = "Comprimento da nadadeira (mm)", ylab = "Frequência", br = 50, cex.main = 2, cex.lab = 2, cex.axis = 1.5) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-10-1.png)<!-- --> ] --- # 6. Densidade (*Density*) ## graphics .pull-left[ ```r par(mar = c(5, 5, 5, 5)) hist(penguins$flipper_length_mm, col = "gray50", border = "gray", main = "Comprimento da nadadeira dos penguins", xlab = "Comprimento da nadadeira (mm)", ylab = "Densidade", br = 50, cex.main = 2, cex.lab = 2, cex.axis = 1.5, prob = TRUE) lines(density(na.omit(penguins$flipper_length_mm))) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-11-1.png)<!-- --> ] --- # 6. Densidade (*Density*) ## graphics .pull-left[ ```r par(mar = c(5, 5, 5, 5)) plot(density(na.omit(penguins$flipper_length_mm)), col = "gray50", main = "Comprimento da nadadeira dos penguins", xlab = "Comprimento da nadadeira (mm)", ylab = "Densidade", cex.main = 2, cex.lab = 2, cex.axis = 1.5) polygon(density(na.omit(penguins$flipper_length_mm)), col = "gray50") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-12-1.png)<!-- --> ] --- # 6. Densidade (*Density*) ## graphics ### Exportar ```r png(here::here("03_dados", "graficos", "plot_densidade.png"), wi = 15, he = 15, un = "cm", res = 300) ``` -- ```r par(mar = c(5, 5, 5, 5)) plot(density(na.omit(penguins$flipper_length_mm)), col = "gray50", main = "Comprimento da nadadeira dos penguins", xlab = "Comprimento da nadadeira (mm)", ylab = "Frequência", cex.main = 2, cex.lab = 2, cex.axis = 1.5) polygon(density(na.omit(penguins$flipper_length_mm)), col = "gray50") ``` -- ```r dev.off() ``` --- class: clear background-image: url(img/package_ggplot2.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [ggplot2](https://ggplot2.tidyverse.org/) --- # 6. Histograma (*Histogram*) ## ggplot2 .pull-left[ ```r ggplot(data = penguins) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-16-1.png)<!-- --> ] --- # 6. Histograma (*Histogram*) ## ggplot2 .pull-left[ ```r ggplot(data = penguins, aes(x = flipper_length_mm)) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-17-1.png)<!-- --> ] --- # 6. Histograma (*Histogram*) ## ggplot2 .pull-left[ ```r ggplot(data = penguins, aes(x = flipper_length_mm)) + geom_histogram() ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-18-1.png)<!-- --> ] --- # 6. Histograma (*Histogram*) ## ggplot2 .pull-left[ ```r ggplot(data = penguins, aes(x = flipper_length_mm)) + geom_histogram(color = "black", fill = "cyan4", bins = 10) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-19-1.png)<!-- --> ] --- # 6. Histograma (*Histogram*) ## ggplot2 .pull-left[ ```r ggplot(data = penguins, aes(x = flipper_length_mm)) + geom_histogram(color = "black", fill = "cyan4", bins = 10, alpha = .5) + labs(title = "Comprimento da nadadeira dos penguins", x = "Comprimento da nadadeira (mm)", y = "Frequência") + theme_bw(base_size = 15) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-20-1.png)<!-- --> ] --- # 6. Histograma (*Histogram*) ## ggplot2 .pull-left[ ```r ggplot(data = penguins, aes(x = flipper_length_mm, fill = species)) + geom_histogram(bins = 10, alpha = .5) + labs(title = "Comprimento da nadadeira dos penguins", fill = "Espécies", x = "Comprimento da nadadeira (mm)", y = "Frequência") + theme_bw(base_size = 15) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-21-1.png)<!-- --> ] --- # 6. Histograma (*Histogram*) ## ggplot2 .pull-left[ ```r ggplot(data = penguins, aes(x = flipper_length_mm, fill = species)) + geom_histogram(bins = 10, alpha = .5, position = "dodge") + labs(title = "Comprimento da nadadeira dos penguins", fill = "Espécies", x = "Comprimento da nadadeira (mm)", y = "Frequência") + theme_bw(base_size = 15) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-22-1.png)<!-- --> ] --- # 6. Histograma (*Histogram*) ## ggplot2 .pull-left[ ```r ggplot(data = penguins, aes(x = flipper_length_mm, fill = species)) + geom_histogram(alpha = .5, position = "identity") + scale_fill_manual(values = c("darkorange", "darkorchid", "cyan4")) + labs(title = "Comprimento da nadadeira dos penguins", fill = "Espécies", x = "Comprimento da nadadeira (mm)", y = "Frequência") + theme_bw(base_size = 15) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-23-1.png)<!-- --> ] --- # 6. Histograma (*Histogram*) ## ggplot2 .pull-left[ ```r ggplot(data = penguins, aes(x = flipper_length_mm, fill = species)) + geom_histogram() + scale_fill_manual(values = c("darkorange", "darkorchid", "cyan4")) + facet_wrap(~ species, ncol = 2, scale = "free_y") + labs(title = "Comprimento da nadadeira dos penguins", fill = "Espécies", x = "Comprimento da nadadeira (mm)", y = "Frequência") + theme_bw(base_size = 15) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-24-1.png)<!-- --> ] --- # 6. Histograma (*Histogram*) ## ggplot2 .pull-left[ ```r ggplot(data = penguins, aes(x = flipper_length_mm, fill = species)) + geom_histogram() + scale_fill_manual(values = c("darkorange", "darkorchid", "cyan4")) + facet_grid(species ~ .) + labs(title = "Comprimento da nadadeira dos penguins", fill = "Espécies", x = "Comprimento da nadadeira (mm)", y = "Frequência") + theme_bw(base_size = 15) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-25-1.png)<!-- --> ] --- # 6. Densidade (*Density*) ## ggplot2 .pull-left[ ```r ggplot(data = penguins) + aes(x = flipper_length_mm) + geom_density(color = "black", fill = "cyan4", alpha = .5) + labs(title = "Comprimento da nadadeira dos penguins", x = "Comprimento da nadadeira (mm)", y = "Densidade") + theme_bw(base_size = 15) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-26-1.png)<!-- --> ] --- # 6. Densidade (*Density*) ## ggplot2 .pull-left[ ```r ggplot(data = penguins, aes(x = flipper_length_mm, fill = species)) + geom_density(alpha = .5) + scale_fill_manual(values = c("darkorange", "darkorchid", "cyan4")) + labs(x = "Comprimento da nadadeira (mm)", y = "Densidade", fill = "Espécie") + theme_bw(base_size = 15) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-27-1.png)<!-- --> ] --- # 6. Histograma (*Histogram*) ## ggplot2 ### Exportar ```r ggplot_densidade <- ggplot(data = penguins, aes(x = flipper_length_mm, fill = species)) + geom_density(alpha = .5) + scale_fill_manual(values = c("darkorange", "darkorchid", "cyan4")) + labs(x = "Comprimento da nadadeira (mm)", y = "Densidade", fill = "Espécie") + theme_bw(base_size = 15) ggsave(filename = here::here("03_dados", "graficos", "histogram_ggplot2.png"), plot = ggplot_densidade, wi = 20, he = 15, un = "cm", dpi = 300) ``` --- class: clear background-image: url(img/package_ggpubr.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [ggpubr](https://rpkgs.datanovia.com/ggpubr/) --- # 6. Histograma (*Histogram*) ## ggpubr .pull-left[ ```r gghistogram(data = penguins, x = "flipper_length_mm", add = "median", color = "species", fill = "species", palette = c("darkorange", "darkorchid", "cyan4"), xlab = "Comprimento da nadadeira (mm)", ylab = "Frequência") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-29-1.png)<!-- --> ] --- # 6. Densidade (*Density*) ## ggpubr .pull-left[ ```r ggdensity(data = penguins, x = "flipper_length_mm", add = "median", color = "species", fill = "species", palette = c("darkorange", "darkorchid", "cyan4"), xlab = "Comprimento da nadadeira (mm)", ylab = "Densidade") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-30-1.png)<!-- --> ] --- # 6. Densidade (*Density*) ## ggpubr ### Exportar ```r ggpubr_densidade <- ggdensity(data = penguins, x = "flipper_length_mm", add = "median", fill = "cyan4", rug = TRUE, add_density = TRUE, xlab = "Comprimento da nadadeira (mm)", ylab = "Densidade") ggsave(filename = here::here("03_dados", "graficos", "densidade_ggpubr.png"), plot = ggpubr_densidade, wi = 20, he = 15, un = "cm", dpi = 300) ``` --- background-image: url(img/plot_pie.png) background-size: 300px background-position: 50% 90% # 7. Gráfico de setores (*Pie chart*) ### **Representa os dados de**: uma coluna ### **Tipo de dado**: categórico ### Proporção ou porcentagem de dados categóricos --- class: clear background-image: url(img/package_graphics.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [graphics](http://search.r-project.org/R/library/graphics/html/00Index.html) --- # 7. Gráfico de setores (*Pie chart*) ### Clássico .pull-left[ ```r par(mar = c(0, 1, 0, 1)) pie(c(280, 60, 20), c("Sky", "Sunny side of pyramid", "Shady side of pyramid"), col = c("#0292D8", "#F7EA39", "#C4B632"), init.angle = -50, border = NA) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-32-1.png)<!-- --> ] --- # 7. Gráfico de setores (*Pie chart*) ### Tabela de frequência ```r # calculo da proporcao penguins_prop <- penguins %>% dplyr::count(species) %>% dplyr::mutate(prop = round(n/sum(n), 4)*100) penguins_prop ``` ``` ## # A tibble: 3 × 3 ## species n prop ## <fct> <int> <dbl> ## 1 Adelie 152 44.2 ## 2 Chinstrap 68 19.8 ## 3 Gentoo 124 36.0 ``` --- # 7. Gráfico de setores (*Pie chart*) ## graphics .pull-left[ ```r par(mar = c(5, 5, 5, 5)) pie(penguins_prop$prop, labels = paste(penguins_prop$prop, "%"), main = "Espécies", col = c("darkorange", "darkorchid", "cyan4")) legend("topright", legend = penguins_prop$species, fill = c("darkorange", "darkorchid", "cyan4")) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-34-1.png)<!-- --> ] --- class: clear background-image: url(img/package_ggplot2.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [ggplot2](https://ggplot2.tidyverse.org/) --- # 7. Gráfico de setores (*Pie chart*) ## ggplot2 .pull-left[ ```r ggplot(data = penguins_prop, aes(x = "", y = prop, fill = species)) + geom_bar(stat = "identity", color = "white") + coord_polar("y", start = 0) + geom_text(aes(label = paste0(prop, "%")), color = "white", position = position_stack(vjust = .5), size = 8) + scale_fill_manual(values = c("darkorange", "purple", "cyan4")) + theme_void() + labs(fill = "Espécie") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-35-1.png)<!-- --> ] --- class: clear background-image: url(img/package_ggpubr.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [ggpubr](https://rpkgs.datanovia.com/ggpubr/) --- # 7. Gráfico de setores (*Pie chart*) ## ggpubr .pull-left[ ```r ggpie(penguins_prop, "prop", label = "prop", lab.pos = "in", lab.font = c(8, "white"), fill = "species", color = "white", palette = c("darkorange", "purple", "cyan4")) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-36-1.png)<!-- --> ] --- class: inverse, center, middle # Mas todos dizem para jogar o gráfico de pizza fora e pedir uma pizza... --- class: inverse, center, middle # ... e eu concordo... --- class: inverse, center, middle # Então vamos usar algo mais saudável: vamos retirar o recheio da pizza... --- background-image: url(img/plot_donut.png) background-size: 300px background-position: 50% 90% # 7. Gráfico de setores (*Donut chart*) ### **Representa os dados de**: uma coluna ### **Tipo de dado**: categórico ### Proporção ou porcentagem de dados categóricos --- class: clear background-image: url(img/package_ggplot2.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [ggplot2](https://ggplot2.tidyverse.org/) --- # 7. Gráfico de setores (*Donut chart*) ## ggplot2 .pull-left[ ```r ggplot(data = penguins_prop, aes(x = 2, y = prop, fill = species)) + geom_bar(stat = "identity") + coord_polar(theta = "y", start = 0) + geom_text(aes(label = paste0(prop, "%")), color = "white", position = position_stack(vjust = .5), size = 5) + scale_fill_manual(values = c("darkorange", "purple", "cyan4")) + xlim(0, 2.5) + theme_void() + theme(legend.position = c(.5, .5), legend.title = element_text(size = 20), legend.text = element_text(size = 15)) + labs(fill = "Espécie") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-37-1.png)<!-- --> ] --- class: clear background-image: url(img/package_ggpubr.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [ggpubr](https://rpkgs.datanovia.com/ggpubr/) --- # 7. Gráfico de setores (*Donut chart*) ## ggpubr .pull-left[ ```r ggdonutchart(penguins_prop, "prop", label = "prop", lab.pos = "in", lab.font = c(7, "white"), fill = "species", color = "white", palette = c("darkorange", "purple", "cyan4")) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-38-1.png)<!-- --> ] --- background-image: url(img/plot_barplot.png) background-size: 300px background-position: 50% 90% # 8. Gráfico de barras (*Bar plot*) ### **Representa os dados de**: duas colunas ### **Modo das colunas**: X = categórico e Y = categórico ### Resume dados de contagens para uma coluna com diversos tipos de dados --- class: clear background-image: url(img/package_graphics.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [graphics](http://search.r-project.org/R/library/graphics/html/00Index.html) --- # 8. Gráfico de barras (*Bar plot*) ## Tabela de frequência ```r # numero de individuos coletados penguins_count <- penguins %>% dplyr::count(species) penguins_count ``` ``` ## # A tibble: 3 × 2 ## species n ## <fct> <int> ## 1 Adelie 152 ## 2 Chinstrap 68 ## 3 Gentoo 124 ``` --- # 8. Gráfico de barras (*Bar plot*) ## graphics .pull-left[ ```r barplot(n ~ species, data = penguins_count, col = c("darkorange", "purple", "cyan4"), main = "Número de indivíduos medido por espécie", xlab = "Espécies", ylab = "Frequência absoluta", cex.main = 1.5, cex.lab = 1.3, cex.axis = 1.2) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-40-1.png)<!-- --> ] --- class: clear background-image: url(img/package_ggplot2.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [ggplot2](https://ggplot2.tidyverse.org/) --- # 8. Gráfico de barras (*Bar plot*) ## ggplot2 .pull-left[ ```r ggplot(data = penguins_count, aes(x = species, y = n, fill = species)) + geom_bar(stat = "identity") + geom_label(aes(label = n), fill = "white") + scale_fill_manual(values = c("darkorange", "purple", "cyan4")) + theme_bw(base_size = 15) + theme(legend.position = "none") + labs(x = "Espécie", y = "Número de indivíduos", fill = "Espécie") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-41-1.png)<!-- --> ] --- # 8. Gráfico de barras (*Bar plot*) ## ggplot2 .pull-left[ ```r ggplot(data = penguins_count, aes(x = species, y = n, fill = species)) + geom_bar(stat = "identity") + geom_label(aes(label = n), fill = "white") + scale_fill_manual(values = c("darkorange", "purple", "cyan4")) + coord_flip() + theme_bw(base_size = 15) + theme(legend.position = "none") + labs(x = "Espécie", y = "Número de indivíduos", fill = "Espécie") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-42-1.png)<!-- --> ] --- class: clear background-image: url(img/package_ggpubr.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [ggpubr](https://rpkgs.datanovia.com/ggpubr/) --- # 9. Gráfico de barras (*Bar plot*) ### ggpubr .pull-left[ ```r ggbarplot(penguins_count, x = "species", y = "n", fill = "species", color = "species", palette = c("darkorange", "purple", "cyan4"), label = TRUE, lab.pos = "in", lab.col = "white", lab.size = 8, main = "Número de indivíduos medido por espécie", xlab = "Espécies", ylab = "Frequência absoluta", legend = "none") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-43-1.png)<!-- --> ] --- # 9. Gráfico de barras (*Bar plot*) ### ggpubr .pull-left[ ```r ggbarplot(penguins_count, x = "species", y = "n", fill = "species", color = "species", palette = c("darkorange", "purple", "cyan4"), label = TRUE, lab.pos = "out", lab.col = "black", lab.size = 8, main = "Número de indivíduos medido por espécie", xlab = "Espécies", ylab = "Frequência absoluta", legend = "none", orientation = "horiz") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-44-1.png)<!-- --> ] --- background-image: url(img/plot_boxplot.png) background-size: 300px background-position: 50% 90% # 9. Gráfico de caixa (*Box plot*) ### **Representa os dados de**: duas colunas ### **Modo das colunas**: X = categórico e Y = contínuo ### Resume informações de medidas contínuas para dois ou mais fatores categóricos --- background-image: url(img/plot_boxplot1.png) background-size: 600px background-position: 50% 70% # 9. Gráfico de caixa (*Box plot*) ### Intervalo inter-quartil (*interquartile range* - IQR) ### Limite inferior e limite superipor (1.5 x IQR) ### Valores exteriores (*outliers*) <br><br><br><br><br><br><br><br><br><br><br> [Understanding Boxplots](https://towardsdatascience.com/understanding-boxplots-5e2df7bcbd51) --- background-image: url(img/plot_boxplot2.png) background-size: 500px background-position: 50% 35% # 9. Gráfico de caixa (*Box plot*) <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [Understanding Boxplots](https://towardsdatascience.com/understanding-boxplots-5e2df7bcbd51) --- class: clear background-image: url(img/package_graphics.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [graphics](http://search.r-project.org/R/library/graphics/html/00Index.html) --- # 9. Gráfico de caixa (*Box plot*) ## graphics .pull-left[ ```r boxplot(flipper_length_mm ~ as.factor(species), data = penguins, col = c("darkorange", "purple", "cyan4"), border = "black", main = "Espécies por amostragens", xlab = "Espécies", ylab = "Comprimento da nadadeira (mm)", cex.main = 1.5, cex.lab = 1.3, cex.axis = 1.2) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-45-1.png)<!-- --> ] --- class: clear background-image: url(img/package_ggplot2.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [ggplot2](https://ggplot2.tidyverse.org/) --- # 9. Gráfico de caixa (*Box plot*) ### ggplott2 .pull-left[ ```r ggplot(data = penguins, aes(x = species, y = flipper_length_mm, fill = species)) + geom_boxplot(width = .3, show.legend = FALSE) + scale_fill_manual(values = c("darkorange", "purple", "cyan4")) + theme_bw(base_size = 15) + labs(x = "Species", y = "Flipper length (mm)") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-46-1.png)<!-- --> ] --- # 9. Gráfico de caixa (*Box plot*) ### ggplott2 .pull-left[ ```r ggplot(data = penguins, aes(x = species, y = flipper_length_mm, fill = species)) + geom_boxplot(width = .3, show.legend = FALSE) + geom_jitter(alpha = .5, show.legend = FALSE, position = position_jitter(width = .1, seed = 0)) + scale_fill_manual(values = c("darkorange", "purple", "cyan4")) + theme_bw(base_size = 15) + labs(x = "Species", y = "Flipper length (mm)") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-47-1.png)<!-- --> ] --- # 10. Gráfico de caixa (*Violin plot*) ### ggplott2 .pull-left[ ```r ggplot(data = penguins, aes(x = species, y = flipper_length_mm, fill = species)) + geom_violin(width = .3, show.legend = FALSE) + geom_jitter(alpha = .5, show.legend = FALSE, position = position_jitter(width = .1, seed = 0)) + scale_fill_manual(values = c("darkorange", "purple", "cyan4")) + theme_bw(base_size = 15) + labs(title = "Pontos com jitter", x = "Species", y = "Flipper length (mm)") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-48-1.png)<!-- --> ] --- class: clear background-image: url(img/package_ggpubr.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [ggpubr](https://rpkgs.datanovia.com/ggpubr/) --- # 9. Gráfico de caixa (*Box plot*) ### ggpubr .pull-left[ ```r ggboxplot(data = penguins, x = "species", y = "flipper_length_mm", add = "jitter", shape = "species", fill = "species", color = "black", palette = c("darkorange", "purple", "cyan4"), xlab = "Comprimento da nadadeira (mm)", ylab = "Frequência absoluta", legend = "none") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-49-1.png)<!-- --> ] --- # 10. Gráfico de caixa (*Violin plot*) ### ggpubr .pull-left[ ```r ggviolin(data = penguins, x = "species", y = "flipper_length_mm", add = "jitter", shape = "species", fill = "species", color = "black", palette = c("darkorange", "purple", "cyan4"), xlab = "Comprimento da nadadeira (mm)", ylab = "Frequência absoluta", legend = "none") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-50-1.png)<!-- --> ] --- background-image: url(img/plot_scatter.png) background-size: 300px background-position: 50% 90% # 10. Gráfico de dispersão (*Scatter plot*) ### **Representa os dados de**: duas colunas ### **Modo das colunas**: X = numérico e Y = numérico ### Plota a relação entre duas variáveis contínuas --- class: clear background-image: url(img/package_graphics.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [graphics](http://search.r-project.org/R/library/graphics/html/00Index.html) --- # 10. Gráfico de dispersão (*Scatter plot*) ## graphics .pull-left[ ```r par(mar = c(5, 5, 1, 1)) plot(bill_depth_mm ~ bill_length_mm, data = penguins, pch = 20, cex = 1.5, xlab = "Comprimento do bico (mm)", ylab = "Profundidade do bico (mm)", cex.lab = 1.5, cex.axis = 1.3, bty = "l") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-51-1.png)<!-- --> ] --- class: clear background-image: url(img/package_ggplot2.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [ggplot2](https://ggplot2.tidyverse.org/) --- # 10. Gráfico de dispersão (*Scatter plot*) ## ggplot2 .pull-left[ ```r ggplot(data = penguins, aes(x = bill_length_mm, y = bill_depth_mm, color = species, shape = species)) + geom_point(size = 3, alpha = .8) + scale_shape_manual(values = c(19, 15, 17)) + scale_color_manual(values = c("darkorange", "purple", "cyan4")) + theme_bw(base_size = 15) + labs(x = "Comprimento do bico (mm)", y = "Profundidade do bico (mm)", color = "Espécies", shape = "Espécies") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-52-1.png)<!-- --> ] --- # 10. Gráfico de dispersão (*Scatter plot*) ## ggplot2 .pull-left[ ```r ggplot(data = penguins, aes(x = bill_length_mm, y = bill_depth_mm, color = species, shape = species)) + geom_point(size = 3, alpha = .8) + geom_smooth(method = "lm", se = FALSE) + scale_shape_manual(values = c(19, 15, 17)) + scale_color_manual(values = c("darkorange", "purple", "cyan4")) + theme_bw(base_size = 15) + labs(x = "Comprimento do bico (mm)", y = "Profundidade do bico (mm)", color = "Espécies", shape = "Espécies") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-53-1.png)<!-- --> ] --- background-image: url(img/gif_data_dino_statistics.gif) background-size: 600px background-position: 50% 70% # 10. Gráfico de dispersão (*Scatter plot*) ### Same Stats, Different Graphs: Generating Datasets with Varied Appearance and Identical Statistics through Simulated Annealing #### Justin Matejka, George Fitzmaurice <br><br><br><br><br><br><br><br><br><br><br><br><br> [Matejka & Fitzmaurice (2017)](https://www.autodeskresearch.com/publications/samestats) --- # 10. Gráfico de dispersão (*Scatter plot*) ## dino .pull-left[ ```r # package library(datasauRus) # data + plot datasaurus_dozen %>% dplyr::filter(dataset == "dino") %>% ggplot() + aes(x = x, y = y) + geom_point(colour = "black", fill = "black", size = 5, alpha = .75, pch = 21) + theme_bw(base_size = 15) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-54-1.png)<!-- --> ] --- # 10. Gráfico de dispersão (*Scatter plot*) ## Todos os plots .pull-left[ ```r datasaurus_dozen %>% ggplot() + aes(x = x, y = y) + geom_point(colour = "black", fill = "black", size = 1, alpha = .75, pch = 21) + facet_wrap(~dataset) + theme_bw(base_size = 15) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-55-1.png)<!-- --> ] --- class: clear background-image: url(img/package_ggpubr.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [ggpubr](https://rpkgs.datanovia.com/ggpubr/) --- # 10. Gráfico de dispersão (*Scatter plot*) ## ggpubr .pull-left[ ```r ggscatter(data = penguins, x = "flipper_length_mm", y = "bill_depth_mm", color = "species", fill = "species", palette = c("darkorange", "purple", "cyan4"), shape = "species", size = 5, xlab = "Comprimento do bico (mm)", ylab = "Profundidade do bico (mm)") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-56-1.png)<!-- --> ] --- # 10. Gráfico de dispersão (*Scatter plot*) ## ggpubr .pull-left[ ```r ggscatter(data = penguins, x = "flipper_length_mm", y = "bill_depth_mm", color = "species", fill = "species", palette = c("darkorange", "purple", "cyan4"), shape = "species", size = 5, xlab = "Comprimento do bico (mm)", ylab = "Profundidade do bico (mm)", ellipse = TRUE, mean.point = TRUE) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-57-1.png)<!-- --> ] --- # 10. Gráfico de dispersão (*Scatter plot*) ## ggpubr .pull-left[ ```r ggscatter(data = datasaurus_dozen %>% dplyr::filter(dataset == "dino"), x = "x", y = "y", size = 5, xlab = "X", ylab = "Y") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-58-1.png)<!-- --> ] --- # 10. Gráfico de dispersão (*Scatter plot*) ## ggpubr .pull-left[ ```r ggscatter(data = datasaurus_dozen, x = "x", y = "y", size = 1, xlab = "X", ylab = "Y", facet.by = "dataset") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-59-1.png)<!-- --> ] --- background-image: url(img/plot_correlogram.png) background-size: 300px background-position: 50% 90% # 11. Gráfico pareado (*Pairs plot*) ### **Representa os dados de**: muitas colunas ### **Modo das colunas**: X = numérico e Y = numérico ### Plota a relação entre duas variáveis contínuas, mas para várias colunas --- class: clear background-image: url(img/package_graphics.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [graphics](http://search.r-project.org/R/library/graphics/html/00Index.html) --- # 11. Gráfico pareado (*Pairs plot*) ## graphics .pull-left[ ```r penguins %>% dplyr::select(body_mass_g, ends_with("_mm")) %>% pairs(pch = 20, upper.panel = NULL) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-60-1.png)<!-- --> ] --- class: clear background-image: url(img/package_ggplot2.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [GGally](http://ggobi.github.io/ggally/) --- # 11. Gráfico pareado (*Pairs plot*) ## GGally .pull-left[ ```r # pacote # install.packages("GGally") library(GGally) penguins %>% dplyr::select(body_mass_g, ends_with("_mm")) %>% ggpairs() + theme_bw(base_size = 15) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-61-1.png)<!-- --> ] --- # 11. Gráfico pareado (*Pairs plot*) ## GGally .pull-left[ ```r penguins %>% dplyr::select(species, sex, body_mass_g, ends_with("_mm")) %>% GGally::ggpairs(aes(color = species)) + scale_colour_manual(values = c("darkorange", "purple", "cyan4")) + scale_fill_manual(values = c("darkorange", "purple", "cyan4")) + theme_bw(base_size = 15) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-62-1.png)<!-- --> ] --- # 11. Gráfico pareado (*Pairs plot*) ## psych .pull-left[ ```r # pacote # install.packages("psych") library(psych) penguins %>% dplyr::select(body_mass_g, ends_with("_mm")) %>% pairs.panels(pch = 20, ellipses = FALSE, density = FALSE, stars = TRUE, hist.col = "gray", digits = 2, rug = FALSE, breaks = 10, ci = TRUE) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-63-1.png)<!-- --> ] --- background-image: url(img/cowplot_graphics.png), url(img/patchwork_graphics.png) background-size: 600px, 350px background-position: 10% 97%, 85% 95% # 12. Combinando gráficos ## Descrição ### Muitas vezes precisamos **combinar gráficos** para representar nossos dados -- ### Essa tarefa pode ser realizada depois da criação dos gráficos em aplicativos como [Inkscape](https://inkscape.org/pt-br/) ou [GIMP](https://www.gimp.org/) -- ### Outras vezes, podemos usar códigos e pacotes do R para fazer essa tarefa --- class: clear background-image: url(img/package_graphics.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [graphics](http://search.r-project.org/R/library/graphics/html/00Index.html) --- # 12. Combinando gráficos ## graphics .pull-left[ ```r par(mfrow = c(1, 2)) boxplot(flipper_length_mm ~ as.factor(species), data = penguins, col = c("darkorange", "purple", "cyan4"), main = "Espécies por amostragens", xlab = "Espécies", ylab = "Comprimento da nadadeira (mm)", cex.main = 1.5, cex.lab = 1.3, cex.axis = 1.2) plot(bill_depth_mm ~ bill_length_mm, data = penguins, pch = 20, cex = 1.5, main = "Comprimento e profundidade do bico", xlab = "Comprimento do bico (mm)", ylab = "Profundidade do bico (mm)", cex.lab = 1.5, cex.axis = 1.3) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-64-1.png)<!-- --> ] --- # 12. Combinando gráficos ## graphics .pull-left[ ```r par(mfrow = c(2, 1)) boxplot(flipper_length_mm ~ as.factor(species), data = penguins, col = c("darkorange", "purple", "cyan4"), main = "Espécies por amostragens", xlab = "Espécies", ylab = "Comprimento da nadadeira (mm)", cex.main = 1.5, cex.lab = 1.3, cex.axis = 1.2) plot(bill_depth_mm ~ bill_length_mm, data = penguins, pch = 20, cex = 1.5, main = "Comprimento e profundidade do bico", xlab = "Comprimento do bico (mm)", ylab = "Profundidade do bico (mm)", cex.lab = 1.5, cex.axis = 1.3) ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-65-1.png)<!-- --> ] --- class: clear background-image: url(img/package_ggplot2.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [ggplot2](https://ggplot2.tidyverse.org/) --- # 12. Combinando gráficos ## ggplot2 .pull-left[ ```r ggplot_boxplot <- ggplot(data = penguins, aes(x = species, y = flipper_length_mm, fill = species)) + geom_boxplot(width = .3, show.legend = FALSE) + geom_jitter(alpha = .5, show.legend = FALSE, position = position_jitter(width = .1, seed = 0)) + scale_fill_manual(values = c("darkorange", "purple", "cyan4")) + theme_bw(base_size = 15) + labs(x = "Species", y = "Flipper length (mm)") ggplot_boxplot ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-66-1.png)<!-- --> ] --- # 12. Combinando gráficos ## ggplot2 .pull-left[ ```r ggplot_scatterplot <- ggplot(data = penguins, aes(x = bill_length_mm, y = bill_depth_mm, color = species, shape = species)) + geom_point(size = 3, alpha = .8) + scale_shape_manual(values = c(19, 15, 17)) + scale_color_manual(values = c("darkorange", "purple", "cyan4")) + theme_bw(base_size = 15) + labs(x = "Comprimento do bico (mm)", y = "Profundidade do bico (mm)", color = "Espécies", shape = "Espécies") ggplot_scatterplot ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-67-1.png)<!-- --> ] --- class: clear background-image: url(img/cowplot_package.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [cowplot](https://wilkelab.org/cowplot/) --- # 12. Combinando gráficos ## cowplot .pull-left[ ```r # pacote # install.packages("cowplot") library(cowplot) # combinacao horizontal plot_grid(ggplot_boxplot, ggplot_scatterplot, align = "h", rel_widths = c(1, 1.5), labels = "AUTO") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-68-1.png)<!-- --> ] --- # 12. Combinando gráficos ## cowplot .pull-left[ ```r # combinacao vertical plot_grid(ggplot_boxplot, ggplot_scatterplot, ncol = 1, align = "v", labels = "AUTO") ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-69-1.png)<!-- --> ] --- class: clear background-image: url(img/patchwork_package.png) background-size: 300px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [patchwork](https://patchwork.data-imaginist.com/) --- # 12. Combinando gráficos ## patchwork .pull-left[ ```r # pacote # install.packages("patchwork") library(patchwork) # combinacao horizontal ggplot_boxplot + ggplot_scatterplot ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-70-1.png)<!-- --> ] --- # 12. Combinando gráficos ## patchwork .pull-left[ ```r # combinacao vertical ggplot_boxplot / ggplot_scatterplot ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-71-1.png)<!-- --> ] --- class: clear background-image: url(img/gganimate_package.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [gganimate](https://gganimate.com/) --- # 13. Gráficos animados ## gganimate .pull-left[ ```r # pacote # devtools::install_github('thomasp85/gganimate') library(gganimate) plot_animate <- ggplot(data = penguins, aes(x = bill_length_mm, y = bill_depth_mm, color = species)) + geom_point() + scale_color_manual(values = c("darkorange", "purple", "cyan4")) + theme_bw(base_size = 15) + labs(x = "Comprimento do bico (mm)", y = "Profundidade do bico (mm)", color = "Espécies", shape = "Espécies") + labs(title = "{closest_state}") + transition_states(species) + enter_grow() + exit_fade() plot_animate ``` ] .pull-right[ ![](05_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-72-1.gif)<!-- --> ] --- # 13. Gráficos animados ## gganimate ### Exportar ```r gganimate::anim_save(filename = here::here("03_dados", "graficos" , "plot_animate.gif"), animation = plot_animate) ``` --- class: clear background-image: url(img/package_plotly.png) background-size: 600px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [plotly](https://plotly.com/r/) --- # 14. Gráficos interativos ## plotly .pull-left[ ```r # pacote # install.packages("plotly") library(plotly) plot_ly(data = penguins, x = ~bill_length_mm, y = ~bill_depth_mm, type = "scatter", color = ~species, colors = c("darkorange", "purple", "cyan4")) %>% layout(xaxis = list(title = "Comprimento do bico (mm)"), yaxis = list(title = "Profundidade do bico (mm)")) ``` ] .pull-right[
] --- # 14. Gráficos interativos ## plotly .pull-left[ ```r plot_ly(data = penguins, x = ~bill_length_mm, y = ~bill_depth_mm, z = ~body_mass_g, type = "scatter3d", color = ~species, colors = c("darkorange", "purple", "cyan4")) %>% layout(scene = list(xaxis = list(title = "Comprimento do bico (mm)"), yaxis = list(title = "Profundidade do bico (mm)"), zaxis = list(title = "Massa (g)"))) ``` ] .pull-right[
] --- # 14. Gráficos interativos ## plotly .pull-left[ ```r plot_penguins_scatter_int <- ggplotly( ggplot(data = penguins, aes(x = bill_length_mm, y = bill_depth_mm, color = species, shape = species)) + geom_point(size = 3, alpha = .8) + geom_smooth(method = "lm", se = FALSE) + scale_shape_manual(values = c(19, 15, 17)) + scale_color_manual(values = c("darkorange", "purple", "cyan4")) + theme_bw(base_size = 15) + labs(x = "Comprimento do bico (mm)", y = "Profundidade do bico (mm)", color = "Espécies", shape = "Espécies")) plot_penguins_scatter_int ``` ] .pull-right[
] --- # 14. Gráficos interativos ## plotly ### Exportar ```r # pacote # install.packages("htmlwidgets") library(htmlwidgets) # export htmlwidgets::saveWidget(widget = plot_penguins_scatter_int, file = here::here("03_dados", "graficos" ,"plot_penguins_scatter_int.html")) ``` --- class: clear background-image: url(img/esquisse_package.png) background-size: 500px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [gganimate](https://dreamrs.github.io/esquisse/) --- # 15. Gráficos usando interface ## esquisse .pull-left[ ```r # pacote #install.packages("esquisse") library(esquisse) # iniciar esquisse::esquisser(iris) esquisse::esquisser(palmerpenguins::penguins) ``` ] .pull-right[ ![](img/esquisse.gif)<!-- --> ] --- class: inverse, center, middle # Dúvidas? --- class: inverse, center, middle # Leitura --- background-image: url(img/geo_geoprocessing02.png) background-size: 800px background-position: 50% 40% # Leitura <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [Xavier-da-Silva (2009)](http://www.ufrrj.br/lga/tiagomarino/artigos/oqueegeoprocessamento.pdf) --- class: inverse, center, middle # Dúvidas? --- class: clear, middle background-image: url(img/gif_frog.gif),url(img/gif_frogs.gif), url(img/package_xaringan.png) background-size: 250px, 500px, 130px background-position: 35% 50%, 90% 55%, 5% 86% ## Maurício Vancine <br><br> Contatos: <svg viewBox="0 0 512 512" style="height:1em;position:relative;display:inline-block;top:.1em;fill:#23373b;" xmlns="http://www.w3.org/2000/svg"> <path d="M502.3 190.8c3.9-3.1 9.7-.2 9.7 4.7V400c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V195.6c0-5 5.7-7.8 9.7-4.7 22.4 17.4 52.1 39.5 154.1 113.6 21.1 15.4 56.7 47.8 92.2 47.6 35.7.3 72-32.8 92.3-47.6 102-74.1 131.6-96.3 154-113.7zM256 320c23.2.4 56.6-29.2 73.4-41.4 132.7-96.3 142.8-104.7 173.4-128.7 5.8-4.5 9.2-11.5 9.2-18.9v-19c0-26.5-21.5-48-48-48H48C21.5 64 0 85.5 0 112v19c0 7.4 3.4 14.3 9.2 18.9 30.6 23.9 40.7 32.4 173.4 128.7 16.8 12.2 50.2 41.8 73.4 41.4z"></path></svg> [mauricio.vancine@gmail.com]() <svg viewBox="0 0 512 512" style="height:1em;position:relative;display:inline-block;top:.1em;fill:#23373b;" xmlns="http://www.w3.org/2000/svg"> <path d="M459.37 151.716c.325 4.548.325 9.097.325 13.645 0 138.72-105.583 298.558-298.558 298.558-59.452 0-114.68-17.219-161.137-47.106 8.447.974 16.568 1.299 25.34 1.299 49.055 0 94.213-16.568 130.274-44.832-46.132-.975-84.792-31.188-98.112-72.772 6.498.974 12.995 1.624 19.818 1.624 9.421 0 18.843-1.3 27.614-3.573-48.081-9.747-84.143-51.98-84.143-102.985v-1.299c13.969 7.797 30.214 12.67 47.431 13.319-28.264-18.843-46.781-51.005-46.781-87.391 0-19.492 5.197-37.36 14.294-52.954 51.655 63.675 129.3 105.258 216.365 109.807-1.624-7.797-2.599-15.918-2.599-24.04 0-57.828 46.782-104.934 104.934-104.934 30.213 0 57.502 12.67 76.67 33.137 23.715-4.548 46.456-13.32 66.599-25.34-7.798 24.366-24.366 44.833-46.132 57.827 21.117-2.273 41.584-8.122 60.426-16.243-14.292 20.791-32.161 39.308-52.628 54.253z"></path></svg> [@mauriciovancine](https://twitter.com/mauriciovancine) <svg viewBox="0 0 496 512" style="height:1em;position:relative;display:inline-block;top:.1em;fill:#23373b;" xmlns="http://www.w3.org/2000/svg"> <path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"></path></svg> [mauriciovancine](https://github.com/mauriciovancine) <svg viewBox="0 0 512 512" style="height:1em;position:relative;display:inline-block;top:.1em;fill:#23373b;" xmlns="http://www.w3.org/2000/svg"> <path d="M326.612 185.391c59.747 59.809 58.927 155.698.36 214.59-.11.12-.24.25-.36.37l-67.2 67.2c-59.27 59.27-155.699 59.262-214.96 0-59.27-59.26-59.27-155.7 0-214.96l37.106-37.106c9.84-9.84 26.786-3.3 27.294 10.606.648 17.722 3.826 35.527 9.69 52.721 1.986 5.822.567 12.262-3.783 16.612l-13.087 13.087c-28.026 28.026-28.905 73.66-1.155 101.96 28.024 28.579 74.086 28.749 102.325.51l67.2-67.19c28.191-28.191 28.073-73.757 0-101.83-3.701-3.694-7.429-6.564-10.341-8.569a16.037 16.037 0 0 1-6.947-12.606c-.396-10.567 3.348-21.456 11.698-29.806l21.054-21.055c5.521-5.521 14.182-6.199 20.584-1.731a152.482 152.482 0 0 1 20.522 17.197zM467.547 44.449c-59.261-59.262-155.69-59.27-214.96 0l-67.2 67.2c-.12.12-.25.25-.36.37-58.566 58.892-59.387 154.781.36 214.59a152.454 152.454 0 0 0 20.521 17.196c6.402 4.468 15.064 3.789 20.584-1.731l21.054-21.055c8.35-8.35 12.094-19.239 11.698-29.806a16.037 16.037 0 0 0-6.947-12.606c-2.912-2.005-6.64-4.875-10.341-8.569-28.073-28.073-28.191-73.639 0-101.83l67.2-67.19c28.239-28.239 74.3-28.069 102.325.51 27.75 28.3 26.872 73.934-1.155 101.96l-13.087 13.087c-4.35 4.35-5.769 10.79-3.783 16.612 5.864 17.194 9.042 34.999 9.69 52.721.509 13.906 17.454 20.446 27.294 10.606l37.106-37.106c59.271-59.259 59.271-155.699.001-214.959z"></path></svg> [mauriciovancine.github.io](https://mauriciovancine.github.io) <br><br><br><br><br> Slides criados via pacote [xaringan](https://github.com/yihui/xaringan) e tema [Metropolis](https://github.com/pat-s/xaringan-metropolis). Animação dos sapos por [@probzz](https://twitter.com/probzz/status/1367613720294170627).