Questão 1
MRT_1F <- c(517.1468515630205, 85.13094142168089, 30.333207896694553, 12.694776264558937, 3.3041601673945418, 1.1823111717498882, 1.1892293502386786)
MRT_3F <- c(156.68929936163462, 11.540837783562276, 0.4512835621696538, 0.4509797929766453, 0.4502068233039181, 0.4496185276300172, 0.4543157082191288)
MRT_5F <- c(83.90319666471157, 0.3068151086494968, 0.30522314133037304, 0.3072588968084928, 0.30655265997285697, 0.3055812715727718, 0.3053297166713006)
MRT_10F <- c(29.55430642951759, 0.19832832665772515, 0.1971923924717474, 0.19796648905716516, 0.19615594370806338, 0.2034569237883263, 0.19617420889447737)
MRT_15F <- c(11.317736530583566, 0.167364215666193, 0.16172168266811013, 0.16701085329580515, 0.1598052657153692, 0.1645934043532696, 0.16216563797118075)
MRT_sem_F <- c(11.93430909937736, 0.6095414637034009, 0.6060645101029295, 0.612167181646899, 0.6146761002685637, 0.6096747087200697, 0.6125810476877268)
clock <- c(0.1, 0.5, 1, 1.5, 2, 2.5, 3)
plot(clock, MRT_1F, type = "o", col = "black", ylim = c(0, max(MRT_1F)), xlab = "Clock", ylab = "MRT", pch=4)
lines(clock, MRT_3F, type = "o", col = "yellow", pch=0)
lines(clock, MRT_5F, type = "o", col = "red", pch=1)
lines(clock, MRT_10F, type = "o", col = "blue", pch=2)
lines(clock, MRT_15F, type = "o", col = "purple", pch=5)
lines(clock, MRT_sem_F, type = "o", col = "green", pch=4)
legend("topright", legend = c("1 Fog", "3 Fogs", "5 Fogs", "10 Fogs", "15 Fogs", "Sem Fog"), col = c("black", "yellow", "red", "blue", "purple", "green"), lty = 1, pch = 1)

layout(matrix(c(1,2,3,4,5,0), nrow=3, byrow = TRUE))
suppressWarnings({
barplot(rbind(MRT_sem_F, MRT_1F), names.arg = clock, beside = TRUE, log="y", col = c("#E6E6E6", "#666666"), xlab = "Clock", ylab = "MRT", legend.text = c("MRT_sem_F", "MRT_1F"), args.legend = list(x = "topright"))
barplot(rbind(MRT_sem_F, MRT_3F), names.arg = clock, beside = TRUE, log="y", col = c("#E6E6E6", "#666666"), xlab = "Clock", ylab = "MRT", legend.text = c("MRT_sem_F", "MRT_3F"), args.legend = list(x = "topright"))
barplot(rbind(MRT_sem_F, MRT_5F), names.arg = clock, beside = TRUE, log="y", col = c("#E6E6E6", "#666666"), xlab = "Clock", ylab = "MRT", legend.text = c("MRT_sem_F", "MRT_5F"), args.legend = list(x = "topright"))
barplot(rbind(MRT_sem_F, MRT_10F), names.arg = clock, beside = TRUE, log="y", col = c("#E6E6E6", "#666666"), xlab = "Clock", ylab = "MRT", legend.text = c("MRT_sem_F", "MRT_10F"), args.legend = list(x = "topright"))
barplot(rbind(MRT_sem_F, MRT_15F), names.arg = clock, beside = TRUE, log="y", col = c("#E6E6E6", "#666666"), xlab = "Clock", ylab = "MRT", legend.text = c("MRT_sem_F", "MRT_15F"), args.legend = list(x = "topright"))
})

Questão 2
v_10_19 <- c(53.8, 43.6, 2.6)
v_20_29 <- c(33.9, 54.2, 11.9)
v_30_39 <- c(2.6, 60.5, 36.8)
v_40_49 <- c(0.0, 21.4, 78.6)
barplot(rbind(v_10_19, v_20_29, v_30_39, v_40_49), names.arg= c("Good","Very Good", "Excellent"), xlab = "Quality Rating", ylab="% of distribution", legend.text = c("$10-19","$20-29","$30-39","$40-49"), args.legend = list(x = "topleft"), main="Quality Ratings per Meal Prices", col = c("red", "orange", "yellow", "green"))

Questão 3
data("airquality")
temp_celsius <- (airquality$Temp - 32) / 1.8
hist(temp_celsius,
main = "Distribuição e Histograma das Temperaturas em Maio (°C)",
xlab = "Temperatura (°C)",
ylab = "Frequência",
col = "lightblue",
border = "black",
probability = TRUE)
lines(density(temp_celsius, na.rm = TRUE), col = "red", lwd = 2)

Questão 4
sales <- read.table("https://training-course-material.com/images/8/8f/Sales.txt",header=TRUE)
sales_totais <- aggregate(SALES ~ COUNTRY, data = sales, sum)
porcentagens <- round(100 * sales_totais$SALES / sum(sales_totais$SALES), 1)
rotulos <- paste(sales_totais$COUNTRY, "-", porcentagens, "%")
cores <- rainbow(length(sales_totais$COUNTRY))
pie(sales_totais$SALES,
labels = rotulos,
col = cores,
main = "Porcentagem de Vendas por País")
legend("topright", legend = sales_totais$COUNTRY, fill = cores)

Questão 5
data("InsectSprays")
boxplot(count ~ spray,
data = InsectSprays,
main = "Contagem de Insetos por Tipo de Inseticida",
xlab = "Tipo de Inseticida",
ylab = "Contagem de Insetos",
col = "yellow",
outline = FALSE)

Questão 7
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(plotly)
## Carregando pacotes exigidos: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
netflix_data <- read.csv("netflix_titles.csv")
netflix_data_filtrado <- netflix_data %>%
filter(!is.na(country)) %>%
filter(!grepl(",", country)) %>%
filter(!grepl("^[[:space:]]*$", country))
conteudos_por_pais <- netflix_data_filtrado %>%
group_by(country) %>%
summarise(qtd = n()) %>%
arrange(desc(qtd))
top10_paises <- conteudos_por_pais %>%
slice_max(order_by = qtd, n = 10)
fig <- plot_ly(top10_paises, labels = ~country, values = ~qtd, type = 'pie') %>%
layout(title = 'Top 10 Países com Mais Conteúdos na Netflix (2019)')
fig
Questão 8
library(dplyr)
library(plotly)
netflix_data <- read.csv("netflix_titles.csv")
netflix_data_filtrado <- netflix_data %>%
filter(!is.na(country)) %>%
filter(!grepl(",", country)) %>%
filter(!grepl("^[[:space:]]*$", country))
conteudos_por_pais <- netflix_data_filtrado %>%
group_by(country) %>%
summarise(qtd = n()) %>%
arrange(desc(qtd))
top10_paises <- conteudos_por_pais %>%
slice_max(order_by = qtd, n = 10) %>%
rename("País" = country, "Total de conteúdos" = qtd)
fig <- plot_ly(
type = 'table',
header = list(
values = c("País", "Total de conteúdos"),
align = c('center', 'center'),
line = list(color = 'black'),
fill = list(color = 'gray'),
font = list(color = 'white', size = 14)
),
cells = list(
values = rbind(top10_paises$`País`, top10_paises$`Total de conteúdos`),
align = c('center', 'center'),
line = list(color = 'black'),
font = list(size = 12)
)
)
fig
Questão 9
library(dplyr)
library(plotly)
netflix_data <- read.csv("netflix_titles.csv")
netflix_data_filtrado <- netflix_data %>%
filter(!is.na(release_year))
netflix_data_filtrado <- netflix_data_filtrado %>%
mutate(decada = floor(release_year / 10) * 10)
conteudo_por_decada <- netflix_data_filtrado %>%
group_by(decada, type) %>%
summarise(qtd = n()) %>%
ungroup()
## `summarise()` has grouped output by 'decada'. You can override using the
## `.groups` argument.
filmes <- conteudo_por_decada %>%
filter(type == "Movie")
series <- conteudo_por_decada %>%
filter(type == "TV Show")
fig <- plot_ly() %>%
add_trace(x = filmes$decada, y = filmes$qtd, type = 'scatter', mode = 'lines+markers',
name = 'Filmes', line = list(color = 'orange'), marker = list(color = 'orange')) %>%
add_trace(x = series$decada, y = series$qtd, type = 'scatter', mode = 'lines+markers',
name = 'Séries', line = list(color = 'blue'), marker = list(color = 'blue')) %>%
layout(title = 'Quantidade de Conteúdos por Década na Netflix',
xaxis = list(title = 'Década'),
yaxis = list(title = 'Quantidade de Conteúdos'),
legend = list(title = list(text = 'Tipo de Conteúdo')))
fig
Questão 10
library(dplyr)
library(plotly)
netflix_data <- read.csv("netflix_titles.csv")
filmes_2000_2010 <- netflix_data %>%
filter(type == "Movie" & release_year > 2000 & release_year < 2010)
filmes_2000_2010 <- filmes_2000_2010 %>%
mutate(primeiro_genero = sapply(strsplit(as.character(listed_in), ","), `[`, 1))
generos_desejados <- c("Dramas", "Action & Adventure", "Comedies")
filmes_selecionados <- filmes_2000_2010 %>%
filter(primeiro_genero %in% generos_desejados)
filmes_selecionados$primeiro_genero <- factor(filmes_selecionados$primeiro_genero, levels = generos_desejados)
contagem_filmes <- filmes_selecionados %>%
group_by(release_year, primeiro_genero) %>%
summarise(qtd = n()) %>%
ungroup()
## `summarise()` has grouped output by 'release_year'. You can override using the
## `.groups` argument.
fig <- plot_ly(contagem_filmes, x = ~release_year, y = ~qtd, color = ~primeiro_genero,
type = 'bar', text = ~qtd, textposition = 'auto',
colors = c("Dramas" = "deepskyblue2", "Action & Adventure" = "darkorange1", "Comedies" = "chartreuse4")) %>%
layout(barmode = 'group',
title = 'Quantidade de Filmes por Gênero (2000-2010)',
xaxis = list(title = 'Ano de Lançamento'),
yaxis = list(title = 'Quantidade de Filmes'),
legend = list(title = list(text = 'Gênero')))
fig