Q1 - Utilizando o dataset Super Heróis do Kaggle construa um gráfico com o ggplot2 mostrando qual universo (Marvel e DC Comics) tem os super-heróis mais fortes? Dica: utilize ‘geom_bar’ para construir o gráfico.
library(tidyverse)
library(dplyr)
herois<-read_csv("herois_completo.csv", na=c("","-","NA"))
dim(herois)
## [1] 660 178
data1 <- herois %>%
filter(super_strength==TRUE) %>%
filter(publisher== "Marvel Comics" | publisher=="DC Comics")
ggplot(data = data1, aes(x = publisher, y=super_strength, fill=publisher)) +
geom_bar(stat="identity") +
theme_classic() +
labs(x = "Universo", y= "Herois com super forca")
Q2 - Utilizando o dataset Super Heróis do Kaggle construa um gráfico com o ggplot2 mostrando quais super-heróis têm mais variedade de superpoderes.
power_max = mutate(herois,
soma = rowSums(select(herois, agility:omniscient))) %>%
mutate(name = herois$name)
ggplot(data=filter(power_max, soma>30), aes(x = name, y = soma)) +
geom_bar(stat="identity") + theme_classic() + labs(x = "Heroi", y = "Soma") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
Q3 - Utilizando o dataset Super Heróis do Kaggle construa um gráfico com o ggplot2 mostrando os poderes comuns dos super-heróis.
powers_comuns = tibble(soma = colSums(select(herois, agility:omniscient)),
nome = names(select(herois, agility:omniscient)))
ggplot(data=filter(powers_comuns, soma>40), aes(x = nome, y = soma, fill = soma)) +
geom_bar(stat="identity") + theme_classic() + labs(x = "Habilidade", y = "Total de super-her昼㸳is", fill = "Total de super-herois") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
Q4 - Utilizando o dataset Super Heróis do Kaggle construa um gráfico com o ggplot2 com relação à distribuição por gênero em cada universo.
data4 <- herois %>%
filter(publisher== "Marvel Comics" | publisher=="DC Comics")
ggplot(data = data4) +
geom_bar(mapping = aes(x = publisher, fill = gender))+
theme_classic()
Q5 - Utilizando o dataset Super Heróis do Kaggle construa um gráfico com o ggplot2 com relação à distribuição da inteligência por gênero em cada universo.
ggplot(data = data4) +
geom_bar(mapping = aes(x = intelligence, fill = gender))+
facet_wrap(~ publisher, nrow = 2)
Q6 - Utilizando o dataset Super Heróis do Kaggle construa um gráfico com o ggplot2 de pontos da coluna weight em função de height. Observe os outliers no gráfico. Crie um novo dataframe sem esses pontos, isto é, crie um novo dataframe chamado herois_limpo, filtrando os heróis com peso e altura entre 1 a 500. Use este dataframe para todos os próximos itens.
ggplot(data = herois) +
geom_point(mapping = aes(x = weight, y = height))
## Warning: Removed 2 rows containing missing values (geom_point).
herois_limpo <- herois %>%
filter((weight>1 & weight<500) & (height>1 & height<500))
ggplot(data = herois_limpo) +
geom_point(mapping = aes(x = weight, y = height))
Q7 - Reproduza os mapas do Brasil mostrados na página https://www.curso-r.com/blog/2017-05-04-mapas-tematicos-3-minutos/ e https://www.curso-r.com/blog/2017-02-21-markercluster/.
a <- matrix(c("AC","AL","AM","AP","BA","CE","DF","ES","GO","MA","MG","MS","MT",
"PA","PB","PE","PI","PR","RJ","RN","RO","RR","RS","SC","SE","SP","TO",
156,3690,2595,254,14582,NA,7124,3343,12740,3347,9958,1150,
4338,4970,NA,7980,2866,8539,32652,2677,1235,256,13760,3264,2013,98763,
473), ncol = 2)
dataset <- data.frame(a)
dataset %>%
head(10)
Q8 - Reproduza o gráfico dinâmico apresentado no link: https://rpubs.com/davimat/graficos_dinamicos.
library(dplyr)
library(gapminder)
head(gapminder)
library(ggplot2)
library(gifski)
theme_set(theme_bw())
p <- ggplot(gapminder, aes(x = gdpPercap, y=lifeExp, size = pop, colour = country)) + geom_point(show.legend = FALSE, alpha = 0.7) +
scale_color_viridis_d() + scale_size(range = c(2, 12)) + scale_x_log10() +
labs(x = "GDP per capita", y = "Life expectancy")+ ggtitle("GDP per capita x Life expectancy")
p
library(gganimate)
p + transition_time(year) +
labs(title = "Year: {frame_time}")