Skip to content

Instantly share code, notes, and snippets.

@nazareno
Created April 13, 2021 15:16
Show Gist options
  • Save nazareno/b4cd505e07446db9b435fbe2175f7fda to your computer and use it in GitHub Desktop.
Save nazareno/b4cd505e07446db9b435fbe2175f7fda to your computer and use it in GitHub Desktop.
---
title: "Discussão sobre Semana 2"
output: html_notebook
---
```{r warning=FALSE, message=FALSE}
library(tidyverse)
library(here)
theme_set(theme_bw())
```
```{r}
# SEMPRE read_csv NUNCA read.csv
clima_tudo = read_csv(
here("data/tempo-jp-cg-pt.csv"),
col_types = cols(
.default = col_double(),
cidade = col_character(),
semana = col_date(format = ""),
ano = col_integer(),
mes = col_integer()
)
)
clima10 = clima_tudo %>%
filter(ano <= 2019, ano >= 2010)
glimpse(clima_tudo)
```
```{r}
clima_tudo %>%
filter(ano == 2019) %>%
ggplot(aes(y = cidade, x = vento_medio)) +
geom_jitter(height = .1, alpha = .7) +
labs(x = "Vento médio na semana (m/s)")
```
FAIXA DE VALORES
- tamanho
- posição
VALORES EXTREMOS
- grupo
- valores individuais nos extremos (outlier)
Função das datas
```{r}
clima_tudo %>%
filter(ano < 2020) %>%
ggplot(aes(y = vento_medio, x = mes)) +
facet_wrap(~ cidade) +
geom_point(alpha = .3) +
scale_x_continuous(breaks = 1:12, labels = c("jan", "fev", 3:12)) +
labs(
x = "mês",
y = "Vento médio na semana (m/s)")
```
```{r}
clima_tudo %>%
ggplot(aes(x = vento_medio)) +
facet_wrap(~ cidade) +
geom_histogram(binwidth = .5) +
labs(x = "Vento médio na semana (m/s)")
```
```{r}
clima_tudo %>%
filter(cidade == "Patos", ano <= 2019, ano >= 2010) %>%
ggplot(aes(x = umidade)) +
facet_wrap(~ ano) +
geom_histogram(binwidth = 5)
```
```{r}
clima_tudo %>%
filter(cidade == "Patos", ano <= 2019, ano >= 2010) %>%
ggplot(aes(x = umidade)) +
facet_wrap(~ ano) +
geom_density(fill = "steelblue")
```
```{r}
clima_tudo %>%
filter(cidade == "Patos") %>%
mutate(ano_label = if_else(ano == 2019, "2019", "outros")) %>%
ggplot(aes(x = mes, y = umidade, color = ano_label)) +
geom_point(alpha = .7) +
scale_color_manual(values = c("black", "gray")) +
scale_x_continuous(breaks = 1:12)
```
```{r}
clima_tudo %>%
filter(cidade == "Patos", ano <= 2019, ano >= 2010) %>%
ggplot(aes(x = ano, y = umidade)) +
geom_jitter(width = .2)
```
```{r}
clima_tudo %>%
filter(cidade == "Patos", ano <= 2019, ano >= 2010) %>%
mutate(ano_label = if_else(ano == 2019, "2019", "outros")) %>%
ggplot(aes(x = ano_label, y = umidade)) +
geom_jitter(width = .2)
```
```{r}
clima_tudo %>%
filter(cidade == "Patos", ano <= 2019, ano >= 2010) %>%
mutate(ano_label = if_else(ano == 2019, "2019", "outros")) %>%
ggplot(aes(x = umidade)) +
facet_wrap(~ ano_label, ncol = 1) +
geom_density()
```
<!-- fiuasydfiasuyhf aksdhf aisudfh aisfuhas ifhas iufhaisufhiausdhfia s udfhais ufhasi udfhasiudf -->
**negrito** *itálico*
[um link](www.ali.com)
###########
```{r}
clima_tudo %>%
mutate(estacao = if_else(mes %in% c(6:8), "Inverno", "Outros")) %>%
ggplot(aes(x = estacao, y = chuva)) +
facet_wrap(~ cidade) +
geom_jitter(alpha = .5, width = .3)
```
```{r}
clima_tudo %>%
mutate(estacao = case_when(
mes %in% c(6:8) ~ "Inverno",
mes %in% c(12, 1, 2) ~ "Verão",
TRUE ~ "Outros"
)) %>%
ggplot(aes(x = estacao, y = chuva)) +
facet_wrap(~ cidade) +
geom_jitter(alpha = .5, width = .3)
```
```{r}
clima_tudo %>%
mutate(estacao = case_when(
mes %in% c(6:8) ~ "Inverno",
mes %in% c(12, 1, 2) ~ "Verão",
TRUE ~ "Outros"
)) %>%
group_by(cidade, estacao) %>%
summarise(chuva = sum(chuva)) %>%
ggplot(aes(y = cidade, x = chuva)) +
facet_wrap(~ estacao) +
geom_col(width = .3)
```
```{r}
clima_tudo %>%
filter(cidade == "Patos", ano == 2019) %>%
ggplot(aes(x = semana)) +
geom_point(mapping = aes(y = vento_medio), color = "orange") +
geom_point(mapping = aes(y = vento_max), color = "brown")
```
```{r}
clima_tudo %>%
filter(cidade == "Patos", ano == 2019) %>%
ggplot(aes(x = semana, y = vento_medio)) +
geom_line(color = "gray") +
geom_point(color = "brown")
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment