class: title-slide <a href="https://github.com/dataAt/intro-analise-de-dados-apresentacao" class="github-corner" aria-label="Código no Github"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#fff; color:#151513; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style> <br><br><br><br> # .font200[Introdução à análise de dados] <br><br> ### Adriano Pereira, Felipe Carvalho & Felipe Menino ### Maio 2022 --- # Agenda <br><br> - .font120[Introdução ao R
<i class="fab fa-r-project faa-float animated faa-slow " style=" color:steelblue;"></i>
] - .font120[Tidyverse
<img src="./images/2_r_img/logo_tidyverse_menor.png" style="height:1em; width:auto; "/>
] - .font120[Visualização de dados
<img src="./images/2_r_img/ggplot2_logo_menor.jpeg" style="height:1em; width:auto; "/>
] <br> --- class: title-slide <br><br><br> # .center.font170[Introdução ao .bold[R]] --- # História do R .font120[ **R** é uma linguagem de programação de alto nível com ambiente voltado para visualização e análise de dados. Em essência foi inspirada na linguagem de programação **S**. Foi iniciamente escrita por **R**oss Ihaka e **R**obert Gentleman no departamento de estatística da universidade de Auckland. ] .pull-left[ <img src="./images/2_r_img/robert_gentleman.jpg" width="50%" height="50%" style="display: block; margin: auto;" /> .center.font70[Robert Gentleman] ] .pull-right[ <img src="./images/2_r_img/ross_lhaka.jpeg" width="45%" height="45%" style="display: block; margin: auto;" /> .center.font70[Ross Ihaka] ] --- class: title-slide <br><br><br> # .center.font170[Conceitos básicos] --- # Conceitos básicos ## Atribuimos valor usando uma seta .bold[`<-`] apontada para a variável <br> .pull-left[ .bold.center.font100[Declaração de variáveis] ```r numerico <- 123 double <- 123.2 inteiro <- 321L complexo <- 321i booleano <- TRUE caractere <- "Bem-vindos" ``` ] -- .pull-right[ .bold.center.font100[Acessando os valores] ```r print(numerico) ## [1] 123 caractere ## [1] "Bem-vindos" ``` ] --- # Tipos de dados estruturados ### Podemos declarar um vetor usando .bold[`c()`] e uma lista usando .bold[`list()`] .pull-left[ .bold.center.font100[Vetores] ```r vetor_int <- c(1, 3, 5) vetor_char <- c("teste", "teste", "teste") vetor_bool <- c(TRUE, TRUE, FALSE) ``` ```r vetor_int ## [1] 1 3 5 ``` ] .pull-right[ .bold.center.font100[Listas] ```r lista_int <- list(1, 3, 5) lista_lista <- list(1, 2.3, list("tres")) ``` ```r lista_lista ## [[1]] ## [1] 1 ## ## [[2]] ## [1] 2.3 ## ## [[3]] ## [[3]][[1]] ## [1] "tres" ``` ] --- # Qual é a diferença? .pull-left[ .bold[Vetores são atômicos, só aceitam um tipo:] ```r vetor_diferente <- c(1, 2.5, TRUE, "ola") vetor_diferente ## [1] "1" "2.5" "TRUE" "ola" ``` ```r is.atomic(vetor_diferente) ## [1] TRUE ``` ] .pull-right[ .bold[Lista não são atômicas, aceitam diversos tipos:] ```r lista_diferente <- list(1, TRUE, "ola") lista_diferente ## [[1]] ## [1] 1 ## ## [[2]] ## [1] TRUE ## ## [[3]] ## [1] "ola" ``` ```r is.atomic(lista_diferente) ## [1] FALSE ``` ] --- # Hierarquia de tipo primitivos ### O .bold[R] possui uma conversão de tipos, sendo assim, garantindo que todo vetor seja atômico. .center[ <img src="./images/2_r_img/tipos.png" width="80%" height="80%" style="display: block; margin: auto;" /> R 4 Data Science - Hadley ] --- # Hierarquia de tipo primitivos .pull-left[ ### Os tipos mais fortes são: .blue[ .font120[ 1. character 2. complex 3. numeric 4. logical ]]] .pull-right[ #### Conversão: ```r v1 <- c(FALSE, "tipo", 5) ``` ] --- # Hierarquia de tipo primitivos .pull-left[ ### Os tipos mais fortes são: .blue[ .font120[ 1. character 2. complex 3. numeric 4. logical]] ] .pull-right[ #### Conversão: ```r v1 <- c(FALSE, "tipo", 5) v1 ## [1] "FALSE" "tipo" "5" ``` ] --- # Hierarquia de tipo primitivos .pull-left[ ### Os tipos mais fortes são: .blue[ .font120[ 1. character 2. complex 3. numeric 4. logical]] ] .pull-right[ #### Conversão: ```r v1 <- c(FALSE, "tipo", 5) v1 ## [1] "FALSE" "tipo" "5" ``` ```r v2 <- c(32, 1, 5i) ``` ] --- # Hierarquia de tipo primitivos .pull-left[ ### Os tipos mais fortes são: .blue[ .font120[ 1. character 2. complex 3. numeric 4. logical]] ] .pull-right[ #### Conversão: ```r v1 <- c(FALSE, "tipo", 5) v1 ## [1] "FALSE" "tipo" "5" ``` ```r v2 <- c(32, 1, 5i) v2 ## [1] 32+0i 1+0i 0+5i ``` ] --- # Hierarquia de tipo primitivos .pull-left[ ### Os tipos mais fortes são: .blue[ .font120[ 1. character 2. complex 3. numeric 4. logical]] ] .pull-right[ #### Conversão: ```r v1 <- c(FALSE, "tipo", 5) v1 ## [1] "FALSE" "tipo" "5" ``` ```r v2 <- c(32, 1, 5i) v2 ## [1] 32+0i 1+0i 0+5i ``` #### Tipos: ```r typeof(v1) ## [1] "character" ``` ```r typeof(v2) ## [1] "complex" ``` ] --- class: title-slide <br><br><br> # .center.font170[Data Frame] <!-- ToDo: A palavra `Data Frame` não é tudo junto ? Tipo `DataFrame` ? --> --- # Data Frame .font120[Matriz composta por linhas e colunas, cujas colunas representam as variáveis (atributos) e as linhas representam observações] <br> .center[ <img src="./images/2_r_img/df_definicao.png" width="60%" height="60%" style="display: block; margin: auto;" /> ] --- # Data Frame .font120[Matriz composta por linhas e colunas, cujas colunas representam as variáveis (atributos) e as linhas representam observações] .pull-left[ .center.font100[Podemos criar um dataframe usando .bold[data.frame()]] ```r meu_df <- data.frame( nome=c("Ana", "João"), idade=c(23, 24), cargo=c("Cientista", "Analista") ) meu_df ## nome idade cargo ## 1 Ana 23 Cientista ## 2 João 24 Analista ``` ] .pull-right[ .center.font100[Acessando os atributos] ```r meu_df$nome ## [1] "Ana" "João" ``` .center.font100[Tipo] ```r typeof(meu_df) ## [1] "list" ``` .center.font100[Classe] ```r class(meu_df) ## [1] "data.frame" ``` ] --- # Estrutura de decisão .pull-left[ .font120[O .bold[.blue[if]] do .bold[R] é bem parecido com o do .bold[Java]] ```r valor_a <- 21 valor_b <- 42 if(valor_a < valor_b){ print("Valor A menor do que o valor B") } else if(valor_a == valor_b){ print("Valor A é igual ao valor B") } else { print("Valor A é maior do que o valor B") } ## [1] "Valor A menor do que o valor B" ``` ] -- .pull-right[ .font120[Dica] ```r ifelse(42 > TRUE, "Verdade universal", "Fake news") ## [1] "Verdade universal" ``` ] --- # Estrutura de repetição .font110[Por outro lado, o .bold[.blue[for]] do .bold[R] parece com a sintaxe do .bold[Python]] ```r meu_vetor <- c(1, 2, 3) for(i in meu_vetor){ print(i) } ## [1] 1 ## [1] 2 ## [1] 3 ``` --- class: title-slide <br><br><br><br> # .center.font170[Tidyverse
<img src="./images/2_r_img/logo_tidyverse.png" style="height:1em; width:auto; "/>
] --- # Tidyverse .pull-left[ .center.font110[Conjunto de pacotes em R para ciência de dados] <img src="./images/2_r_img/tidy_workflow.png" width="100%" height="100%" style="display: block; margin: auto;" /> .center.font50[http://www.seec.uct.ac.za/r-tidyverse] ] -- .pull-right[ .center.font110[Processo de ciência de dados] <img src="./images/2_r_img/data-science-process.png" width="100%" height="100%" style="display: block; margin: auto;" /> .center.font50[Doing Data Science - Rachel Schutt] ] --- # Tidyverse .pull-left[ .center.font110[Conjunto de pacotes em R para ciência de dados] <img src="./images/2_r_img/tidy_workflow_1.png" width="100%" height="100%" style="display: block; margin: auto;" /> .center.font50[http://www.seec.uct.ac.za/r-tidyverse] ] .pull-right[ .center.font110[Processo de ciência de dados] <img src="./images/2_r_img/data-science-process_1.png" width="100%" height="100%" style="display: block; margin: auto;" /> .center.font50[Doing Data Science - Rachel Schutt] ] --- # Tidyverse .pull-left[ .center.font110[Conjunto de pacotes em R para ciência de dados] <img src="./images/2_r_img/tidy_workflow_2.png" width="100%" height="100%" style="display: block; margin: auto;" /> .center.font50[http://www.seec.uct.ac.za/r-tidyverse] ] .pull-right[ .center.font110[Processo de ciência de dados] <img src="./images/2_r_img/data-science-process_2.png" width="100%" height="100%" style="display: block; margin: auto;" /> .center.font50[Doing Data Science - Rachel Schutt] ] --- # Tidyverse .pull-left[ .center.font110[Conjunto de pacotes em R para ciência de dados] <img src="./images/2_r_img/tidy_workflow_3.png" width="100%" height="100%" style="display: block; margin: auto;" /> .center.font50[http://www.seec.uct.ac.za/r-tidyverse] ] .pull-right[ .center.font110[Processo de ciência de dados] <img src="./images/2_r_img/data-science-process_3.png" width="100%" height="100%" style="display: block; margin: auto;" /> .center.font50[Doing Data Science - Rachel Schutt] ] --- # Leitura e escrita de dados - .bold[readr] .pull-left[ .center.font120[Leitura] ```r library(readr) # Leitura dos dados star_wars <- readr::read_csv(file = "data/starwars.csv") ## Rows: 87 Columns: 10 ## ── Column specification ──────────────────────────────────────────────────────── ## Delimiter: "," ## chr (7): name, hair_color, skin_color, eye_color, gender, homeworld, species ## dbl (3): height, mass, birth_year ## ## ℹ 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. ``` ] .pull-right[ .center.font120[Escrita] ```r # escrita readr::write_csv(x = star_wars, path = "data/dado.csv") ``` ] --- # Manipulação de dados - .bold[dplyr] Para manipular nosso dataframe, vamos usar o pacote .blue[dplyr]. Métodos básicos: .center[ <img src="./images/2_r_img/dplyr_verbs.jpg" width="70%" height="70%" style="display: block; margin: auto;" /> .center.font80[R for Data Science - Garrett Grolemund] ] --- # Seleção e Filtro .pull-left[ .font120[Para facilitar a seleção dos atributos e tirar .bold[.blue[$]], vamos usar o .bold[.blue[select()]]]: ```r library(dplyr) selecao <- dplyr::select(star_wars, name, hair_color) head(selecao, 3) ## # A tibble: 3 × 2 ## name hair_color ## <chr> <chr> ## 1 Luke Skywalker blond ## 2 C-3PO <NA> ## 3 R2-D2 <NA> ``` ] .pull-right[ .font120[Para filtrar por um valor específico, usamos .bold[.blue[filter()]]]: ```r filtro <- dplyr::filter(star_wars, species == "Droid" & skin_color == "gold") filtro ## # A tibble: 1 × 10 ## name height mass hair_color skin_color eye_color birth_year gender homeworld ## <chr> <dbl> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 C-3PO 167 75 <NA> gold yellow 112 <NA> Tatooine ## # … with 1 more variable: species <chr> ``` ] --- # Agrupamento e agregação .pull-left[ .font120[Para criar grupos usamos a função .bold[.blue[group_by()]]] ```r agrupamento <- dplyr::group_by(star_wars, species) head(agrupamento, 3) ## # A tibble: 3 × 10 ## # Groups: species [2] ## name height mass hair_color skin_color eye_color birth_year gender homeworld ## <chr> <dbl> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke… 172 77 blond fair blue 19 male Tatooine ## 2 C-3PO 167 75 <NA> gold yellow 112 <NA> Tatooine ## 3 R2-D2 96 32 <NA> white, bl… red 33 <NA> Naboo ## # … with 1 more variable: species <chr> ``` ] .pull-right[ .font120[Para criarmos uma agregação do nosso agrupamento, usamos .bold[.blue[summarise()]] e para ordenarmos .bold[.blue[arrange()]]]: ```r media_grupo <- dplyr::summarise(agrupamento, media = mean(height, na.rm = TRUE)) media_grupo_order <- dplyr::arrange(media_grupo, desc(media)) head(media_grupo_order, 3) ## # A tibble: 3 × 2 ## species media ## <chr> <dbl> ## 1 Quermian 264 ## 2 Wookiee 231 ## 3 Kaminoan 221 ``` ] --- # Transformação de atributos .font120[Para criar/transformar novos atributos, usa-se .bold[.blue[mutate()]]]: ```r # conversão de cm para metros star_wars <- dplyr::mutate(star_wars, height = height/100) head(star_wars, 3) ## # A tibble: 3 × 10 ## name height mass hair_color skin_color eye_color birth_year gender homeworld ## <chr> <dbl> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke… 1.72 77 blond fair blue 19 male Tatooine ## 2 C-3PO 1.67 75 <NA> gold yellow 112 <NA> Tatooine ## 3 R2-D2 0.96 32 <NA> white, bl… red 33 <NA> Naboo ## # … with 1 more variable: species <chr> ``` --- # Aplicando os métodos <!-- ToDo: Acho que estes códigos todos juntos não estão limpos, podia criar uns bloquinhos separados para um conjunto de dois códigos para cada bloco, ou algo assim tlg --> .pull-left[ .font120[Seleção] ```r selecao <- dplyr::select(star_wars, -hair_color, -mass) ``` .font120[Filtro] ```r filtro <- dplyr::filter(selecao, eye_color == "blue") ``` .font120[Agrupamento] ```r agrupamento <- dplyr::group_by(filtro, species) ``` ] .pull-right[ .font120[Agregação] ```r media_grupo <- dplyr::summarise(agrupamento, media = mean(height, na.rm = TRUE)) ``` .font120[Ordenação] ```r media_grupo_order <- dplyr::arrange(media_grupo, desc(media)) ``` ``` ## # A tibble: 3 × 2 ## species media ## <chr> <dbl> ## 1 Wookiee 2.31 ## 2 Chagrian 1.96 ## 3 Tholothian 1.84 ``` ] --- # Facilitando a vida com o operador .bold[pipe] (.bold[%>%]) .font120[O .bold[.blue[pipe]] passa a resposta da primeira atribuição para o primeiro parâmetro da função seguinte]: ```r library(magrittr) media_grupo <- star_wars %>% dplyr::select(-hair_color, -mass) %>% dplyr::filter(eye_color == "blue") %>% dplyr::group_by(species) %>% dplyr::summarise(media = mean(height, na.rm = TRUE)) %>% dplyr::arrange(desc(media)) ``` ```r head(media_grupo, 2) ## # A tibble: 2 × 2 ## species media ## <chr> <dbl> ## 1 Wookiee 2.31 ## 2 Chagrian 1.96 ``` --- # Facilitando a vida com o operador .bold[pipe] (.bold[%>%]) .pull-left[ .center.font120[Sem pipe] ```r # Seleção selecao <- dplyr::select(star_wars, -hair_color, -mass) # Filtro filtro <- dplyr::filter(selecao, eye_color == "blue") # Agrupamento agrupamento <- dplyr::group_by(filtro, species) # Agregação media_grupo <- dplyr::summarise(agrupamento, media = mean(height, na.rm = TRUE)) # Ordenação media_grupo_order <- dplyr::arrange(media_grupo, desc(media)) ``` ] .pull-right[ .center.font120[Com pipe] ```r media_grupo <- star_wars %>% dplyr::select(-hair_color, -mass) %>% dplyr::filter(eye_color == "blue") %>% dplyr::group_by(species) %>% dplyr::summarise(media = mean(height, na.rm = TRUE)) %>% dplyr::arrange(desc(media)) ``` ] --- class: title-slide <br><br><br> # .center.font170[Exemplo de análise de dados] --- # Exemplo de análise de dados Dado de série temporal da [temperatura da superfície terrestre](https://www.kaggle.com/berkeleyearth/climate-change-earth-surface-temperature-data) <img src="./images/2_r_img/kaggle_img.png" width="60%" height="60%" style="display: block; margin: auto;" /> .center.font70[Fonte: Berkeley Earth] --- # Exemplo de análise ```r # Leitura dos dados de mudança climática temperature_countries <- readr::read_csv("./data/GlobalLandTemperaturesByCountry.csv") # Leitura e seleção dos dados de continentes continent <- readr::read_csv("./data/countryContinent.csv") %>% dplyr::select(country, continent) # Seleção do atributo continente ``` ```r head(temperature_countries, 2) ## # A tibble: 2 × 4 ## dt AverageTemperature AverageTemperatureUncertainty Country ## <date> <dbl> <dbl> <chr> ## 1 1743-11-01 4.38 2.29 Åland ## 2 1743-12-01 NA NA Åland ``` ```r tail(temperature_countries, 2) ## # A tibble: 2 × 4 ## dt AverageTemperature AverageTemperatureUncertainty Country ## <date> <dbl> <dbl> <chr> ## 1 2013-08-01 19.8 0.717 Zimbabwe ## 2 2013-09-01 NA NA Zimbabwe ``` --- # Exemplo de análise .pull-left[ .center.font110[Filtro a partir do ano 2000 e extração da média anual] ```r year_temperature <- temperature_countries %>% dplyr::filter(dt > "2000-01-01") %>% dplyr::mutate(dt = lubridate::year(dt)) %>% dplyr::group_by(Country, dt) %>% dplyr::summarise(year_mean = mean(AverageTemperature)) ``` ``` ## # A tibble: 3 × 3 ## # Groups: Country [1] ## Country dt year_mean ## <chr> <dbl> <dbl> ## 1 Afghanistan 2000 16.7 ## 2 Afghanistan 2001 15.8 ## 3 Afghanistan 2002 15.5 ``` ] .pull-right[ .center.font110[Junção dos continentes com cada país] ```r continent_temperature <- year_temperature %>% dplyr::rename(country = Country) %>% dplyr::left_join(continent, by="country") %>% dplyr::filter(!is.na(continent)) ``` ``` ## # A tibble: 3 × 4 ## # Groups: country [1] ## country dt year_mean continent ## <chr> <dbl> <dbl> <chr> ## 1 Afghanistan 2000 16.7 Asia ## 2 Afghanistan 2001 15.8 Asia ## 3 Afghanistan 2002 15.5 Asia ``` ] <!-- ToDo: Achei que estes textos ficaram muito grudados na parte de baixo da apresentação, o que acha ? --> -- .center.font80[.bold[ Qual o continente que registrou a maior temperatura anual? Qual o ano com a maior média de temperatura registrada?]] --- # Exemplo de análise .pull-left[ .center.font80[.bold[Qual o continente que registrou a maior temperatura anual?]] ```r continent_temperature %>% dplyr::group_by(continent) %>% summarise(maior_temp = max(year_mean, na.rm = TRUE)) ## # A tibble: 5 × 2 ## continent maior_temp ## <chr> <dbl> ## 1 Africa 30.3 ## 2 Americas 29.0 ## 3 Asia 29.7 ## 4 Europe 20.3 ## 5 Oceania 27.9 ``` ] .pull-right[ .center.font80[.bold[Qual foi o ano com a maior média de temperatura registrada??]] ```r continent_temperature %>% dplyr::group_by(dt, continent) %>% dplyr::summarise(maior_temp = max(year_mean, na.rm = TRUE)) %>% dplyr::arrange(desc(maior_temp)) %>% head(5) ## # A tibble: 5 × 3 ## # Groups: dt [5] ## dt continent maior_temp ## <dbl> <chr> <dbl> ## 1 2000 Africa 30.3 ## 2 2010 Africa 30.1 ## 3 2012 Africa 29.9 ## 4 2009 Africa 29.9 ## 5 2011 Africa 29.8 ``` ] --- class: title-slide <br><br> # .center[.font170[Visualização de dados]
<i class="fas fa-chart-bar faa-tada animated "></i>
] --- # Pacotes de visualização ## As bibliotecas de visualização de dados `ggplot2` e `plotnine` são baseadas na obra .bold[The Grammar of Graphics], a qual apresenta uma grámatica para elaboração de gráficos. Tal gramática é composta por camadas, as quais descrevem os componentes do gráfico. .pull-left[ .center.font110[Camadas de componentes gráficos] <img src="./images/2_r_img/ggplot-2.png" width="70%" height="70%" style="display: block; margin: auto;" /> ] -- .pull-right[ .center.font110[Sintaxe do ggplot/plotnine] ```r ggplot(data = <DATA>, aes(<MAPPINGS>)) + <GEOM_FUNCTION>( mapping = aes(<MAPPINGS>), stat = <STAT>, position = <POSITION>) + <COORDINATE_FUNCTION> + <FACET_FUNCTION> ``` ] --- # Mapeamento estético ### A estética descreve cada aspecto de um dado elemento gráfico. Descrevemos as posições (`position`) por um valor x e y, mas outros sistemas de coordenadas são possíveis. É possível alterar a forma (`shape`), tamanho (`size`) e cor (`size`) dos elementos. .center[ <img src="./images/2_r_img/aes_ggplot.png" width="80%" height="80%" style="display: block; margin: auto;" /> .center.font80[Fundamentals of Data Visualization - Claus O. Wilke] ] --- # Objetos geométricos .center[ <img src="./images/2_r_img/ggplot.png" width="38%" height="38%" style="display: block; margin: auto;" /> .center.font60[Fundamentals of Data Visualization - Claus O. Wilke] ] --- # Exemplo com R - Gráfico de dispersão .pull-left[ .center.font100[Mapeamento estético] ```r library(ggplot2) ggplot(iris, aes(x = Petal.Width, y = Petal.Length, color = Species)) ``` <img src="apresencao_final_files/figure-html/unnamed-chunk-55-1.png" style="display: block; margin: auto;" /> ] -- .pull-right[ .center.font100[Objeto geométrico] ```r ggplot(iris, aes(x = Petal.Width, y = Petal.Length, color = Species)) + geom_point() ``` <img src="apresencao_final_files/figure-html/unnamed-chunk-56-1.png" style="display: block; margin: auto;" /> ] --- # Exemplo com R - Gráfico de colunas .pull-left[ .center.font100[Mapeamento estético e objeto geométrico] ```r ggplot(data = diamonds) + stat_count(mapping = aes(x = cut)) ``` <img src="apresencao_final_files/figure-html/unnamed-chunk-57-1.png" style="display: block; margin: auto;" /> ] -- .pull-right[ .center.font100[Sistema de coordenadas] ```r ggplot(data = diamonds) + stat_count(mapping = aes(x = cut)) + coord_flip() ``` <img src="apresencao_final_files/figure-html/unnamed-chunk-58-1.png" style="display: block; margin: auto;" /> ] --- # Exemplo com Python - Gráfico de dispersão .pull-left[ .center.font100[Mapeamento estético] ```python from plotnine import * from plotnine.data import mtcars, diamonds ggplot(mtcars, aes(x = 'mpg', y = 'disp')) ``` <img src="./images/python/ggplot_1.png" width="85%" height="85%" style="display: block; margin: auto;" /> ] -- .pull-right[ .center.font100[Objeto geométrico] ```python (ggplot(mtcars, aes(x = 'mpg', y = 'disp', color = 'factor(am)')) + geom_point()) ``` <img src="./images/python/ggplot_2.png" width="100%" height="100%" style="display: block; margin: auto;" /> ] --- # Exemplo com Python - Gráfico de colunas .pull-left[ .center.font100[Mapeamento estético e objeto geométrico] ```python (ggplot(data = diamonds) + stat_count(mapping = aes(x = 'cut'))) ``` <img src="./images/python/ggplot_3.png" width="85%" height="85%" style="display: block; margin: auto;" /> ] -- .pull-right[ .center.font100[Sistema de coordenadas] ```python (ggplot(data = diamonds) + stat_count(mapping = aes(x = 'cut')) + coord_flip()) ``` <img src="./images/python/ggplot_4.png" width="85%" height="85%" style="display: block; margin: auto;" /> ] --- class: title-slide <br><br> # .center[.font170[Indo além]
<i class="fas fa-rocket faa-tada animated "></i>
] --- # Exemplo - Gráfico de coordenadas paralelas .pull-left[ <br><br><br> ```r iris %>% dplyr::mutate(id = 1:nrow(iris)) %>% tidyr::gather(atributos, valores, -Species, -id) %>% ggplot(., aes(x = atributos, y = valores, color = Species, group = id)) + geom_line(size=0.55) + labs(x = "Atributos", y = "Valores", title = "Coordenadas Paralelas - Iris", caption = "Fonte: dataAt") + theme_bw() + theme(plot.title = element_text(hjust= 0.5, margin = margin(b = 7))) ``` ] .pull-right[ <img src="apresencao_final_files/figure-html/unnamed-chunk-64-1.png" style="display: block; margin: auto;" /> ] --- # Exemplo - Gráfico de coordenadas paralelas .pull-left[ <br><br><br> ```r iris %>% dplyr::mutate(id = 1:nrow(iris)) %>% tidyr::gather(atributos, valores, -Species, -id) %>% ggplot(., aes(x = atributos, y = valores, color = Species, group = id)) + geom_line(size=0.55) + facet_grid(~Species) + labs(x = "Atributos", y = "Valores", title = "Coordenadas Paralelas - Iris") + theme_bw() + theme(plot.title = element_text(hjust= 0.5, margin = margin(b = 7)), axis.text.x = element_text(angle = 90)) ``` ] .pull-right[ <img src="apresencao_final_files/figure-html/unnamed-chunk-66-1.png" style="display: block; margin: auto;" /> ] --- class: title-slide <br><br> .center.font300[Extensões do ggplot] <br> .center.font200[(Somente em R)] --- # Lemon package .pull-left[ <br><br><br> ```r amost_diam %>% ggplot(., aes(x = as.factor(cut), y = price, color = clarity)) + geom_point(position=position_jitter(width=0.08)) + coord_flex_cart(bottom=brackets_horisontal(), left=capped_vertical('both')) + theme_light() + theme(panel.border=element_blank(), axis.line = element_line(), plot.title = element_text(hjust= 0.5, margin = margin(b = 7))) + labs(x = "Qualidade do corte", y = "Preço em US", title = "Gráfico de bolhas - Diamonds") ``` ] .pull-right[ <img src="apresencao_final_files/figure-html/unnamed-chunk-69-1.png" style="display: block; margin: auto;" /> ] --- class: title-slide <br><br> .center.font300[Obrigado!] <!-- Fim da parte de visualização-->