Este relatorio apresenta a atividade Exercicio 11 [Storytelling & R Markdown], integrando analise de dados em R com comunicacao visual e narrativa. O foco esta em organizar resultados de forma clara, criar visualizacoes que destaquem insights e estruturar o documento em R Markdown para publicacao.
arquivos_esperados <- c(
"Treatment.csv",
"Catfish.csv",
"Forbes2000_V2.csv",
"Universal2023_ResultadoPreliminar.xls"
)
disponibilidade <- tibble(
arquivo = arquivos_esperados,
existe = file.exists(arquivos_esperados)
)
DT::datatable(disponibilidade, options = list(pageLength = 10))
data("Forbes2000", package = "HSAUR")
forbes <- Forbes2000
forbes_ranking <- forbes %>%
arrange(desc(marketvalue), name) %>%
mutate(ranking = row_number())
forbes_ranking %>%
select(ranking, name, category, marketvalue) %>%
slice(1:10) %>%
DT::datatable(options = list(pageLength = 10))
texto <- c(
"Joao tem 27 anos e telefone (555) 123-4567.",
"Maria tem 35 anos, email maria.silva@exemplo.com e telefone 555-999-1111."
)
padrao_idade <- "\\b\\d+\\s+anos\\b"
padrao_telefone <- "(?:\\(\\d{3}\\)\\s?\\d{3}-\\d{4}|\\d{3}-\\d{3}-\\d{4})"
padrao_email <- "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}"
idades <- stringr::str_extract_all(texto, padrao_idade)
telefones <- stringr::str_extract_all(texto, padrao_telefone)
emails <- stringr::str_extract_all(texto, padrao_email)
list(idades = idades, telefones = telefones, emails = emails)
## $idades
## $idades[[1]]
## [1] "27 anos"
##
## $idades[[2]]
## [1] "35 anos"
##
##
## $telefones
## $telefones[[1]]
## [1] "(555) 123-4567"
##
## $telefones[[2]]
## [1] "555-999-1111"
##
##
## $emails
## $emails[[1]]
## character(0)
##
## $emails[[2]]
## [1] "maria.silva@exemplo.com"
# Forbes2000 (fallback HSAUR)
resp_1234 <- forbes_ranking %>% filter(ranking == 1234) %>% select(name, category)
resp_198 <- forbes_ranking %>% filter(ranking == 198) %>% select(name, category)
resp_45_tech <- forbes_ranking %>%
filter(category == "Technology hardware & equipment", ranking == 45) %>%
select(name)
list(resp_1234 = resp_1234, resp_198 = resp_198, resp_45_tech = resp_45_tech)
## $resp_1234
## name category
## 1038 Doral Financial Banking
##
## $resp_198
## name category
## 306 Gannett Media
##
## $resp_45_tech
## [1] name
## <0 linhas> (ou row.names de comprimento 0)
media_price <- ggplot2::diamonds %>%
filter(cut == "Very Good", carat > 0.7) %>%
summarise(media = mean(price, na.rm = TRUE))
cor_menor_price <- ggplot2::diamonds %>%
filter(carat > 0.5) %>%
arrange(price) %>%
slice(1) %>%
pull(color)
prop_premium <- mean(ggplot2::diamonds$cut == "Premium")
list(media_price = media_price, cor_menor_price = cor_menor_price, prop_premium = prop_premium)
## $media_price
## # A tibble: 1 × 1
## media
## <dbl>
## 1 6512.
##
## $cor_menor_price
## [1] H
## Levels: D < E < F < G < H < I < J
##
## $prop_premium
## [1] 0.255673
data("Fertility", package = "AER")
trecho_fertility <- Fertility %>% select(age, work) %>% slice(35:50)
prop_morekids_work30 <- Fertility %>%
filter(work > 30) %>%
summarise(prop = mean(morekids == "yes", na.rm = TRUE))
prop_male_22_24 <- Fertility %>%
filter(age >= 22, age <= 24) %>%
summarise(prop = mean(gender1 == "male", na.rm = TRUE))
list(
trecho = trecho_fertility,
prop_morekids_work30 = prop_morekids_work30,
prop_male_22_24 = prop_male_22_24
)
## $trecho
## age work
## 1 28 20
## 2 33 12
## 3 32 0
## 4 26 52
## 5 32 52
## 6 28 0
## 7 32 40
## 8 35 0
## 9 33 0
## 10 32 42
## 11 29 0
## 12 29 52
## 13 31 0
## 14 30 51
## 15 28 0
## 16 29 0
##
## $prop_morekids_work30
## prop
## 1 0.3065813
##
## $prop_male_22_24
## prop
## 1 0.5036608
forbes_ranking %>%
select(ranking, name, country, category, marketvalue) %>%
slice(1:100) %>%
DT::datatable(options = list(pageLength = 10, scrollX = TRUE))
ggplot(ggplot2::diamonds, aes(carat, price, color = cut)) +
geom_point(alpha = 0.2, size = 0.6) +
labs(title = "Relacao entre carat e preco", x = "Carat", y = "Preco") +
theme_minimal()
forbes_ranking %>%
count(category, sort = TRUE) %>%
slice(1:10) %>%
ggplot(aes(reorder(category, n), n)) +
geom_col(fill = "#2C7FB8") +
coord_flip() +
labs(title = "Top 10 categorias em Forbes2000", x = "Categoria", y = "Quantidade") +
theme_minimal()
No storytelling com dados, a narrativa orienta o leitor, a visualizacao destaca o padrao, e os dados sustentam a argumentacao. Assim, os resultados deixam de ser apenas numeros e passam a apoiar decisao.