Questões
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)
layout(matrix(c(1, 2), 2, 1, byrow = TRUE))
par(mar = c(4, 4, 4, 2))
# Gráfico 1: Linha
plot(clock, MRT_1F, type = "o", col = "black", pch = 16, xlab = "Clock", ylab = "MRT Values", main = "MRT Values vs Clock", ylim = c(0, max(MRT_1F)))
lines(clock, MRT_3F, type = "o", col = "red", pch = 16)
lines(clock, MRT_5F, type = "o", col = "green", pch = 16)
lines(clock, MRT_10F, type = "o", col = "blue", pch = 16)
lines(clock, MRT_15F, type = "o", col = "purple", pch = 16)
lines(clock, MRT_sem_F, type = "o", col = "orange", pch = 16)
legend("topright", legend = c("MRT_1F", "MRT_3F", "MRT_5F", "MRT_10F", "MRT_15F", "MRT_sem_F"), col = c("black", "red", "green", "blue", "purple", "orange"), pch = 16)
barplot(height = rbind(MRT_1F, MRT_3F, MRT_5F, MRT_10F, MRT_15F, MRT_sem_F), beside = TRUE, log = "y", col = c("#E6E6E6", "#666666", "#E6E6E6", "#666666", "#E6E6E6", "#666666"), names.arg = clock, xlab = "Clock", ylab = "MRT Values (Log Scale)", main = "MRT Values in Log Scale vs Clock", ylim = c(0.1, max(MRT_1F)), args.legend = list(x = "topright", bty = "n"))

Questão 2
qualidade <- rep(c("Boa", "Muito Boa", "Excelente"), each = 4)
preco <- rep(c("$10-19", "$20-29", "$30-39", "$40-49"), times = 3)
porcentagem <- c(53.8, 33.9, 2.6, 0.0, 43.6, 54.2, 60.5, 21.4, 2.6, 11.9, 36.8, 78.6)
df <- data.frame(qualidade, preco, porcentagem)
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(tidyr)
df_wide <- df %>%
pivot_wider(names_from = preco, values_from = porcentagem, values_fill = 0)
barplot(as.matrix(df_wide[,-1]), beside = FALSE, col = c("lightgreen", "lightblue", "lightpink"), legend.text = df_wide$qualidade, ylab = "Porcentagem", xlab = "Categoria de Preço", main = "Distribuição da Qualidade por Categoria de Preço", args.legend = list(x = "topright"))

Questão 3
data(airquality)
airquality$TempC <- (airquality$Temp - 32) / 1.8
hist(airquality$TempC, main = "Histograma das Temperaturas em Maio", xlab = "Temperatura (°C)", col = "lightblue", breaks = 20, freq = FALSE)
lines(density(airquality$TempC), col = "red", lwd = 2)

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

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

Questão 6
adjust_data <- function(file) {
df <- read.csv(file)
df$currentTime <- as.POSIXct(df$currentTime, format = "%Y-%m-%d %H:%M:%S")
df$usedMemory <- as.character(df$usedMemory)
df$usedMemory <- gsub("TB", "*1000000", df$usedMemory)
df$usedMemory <- gsub("GB", "*1024", df$usedMemory)
df$usedMemory <- gsub("MB", "", df$usedMemory)
df$usedMemory <- sapply(df$usedMemory, function(x) eval(parse(text = x)))
return(df)
}
df_0.1 <- adjust_data("monitoringCloudData_0.1.csv")
df_0.5 <- adjust_data("monitoringCloudData_0.5.csv")
df_1 <- adjust_data("monitoringCloudData_1.csv")
df_none <- adjust_data("monitoringCloudData_NONE.csv")
par(mfrow = c(2, 2))
plot(df_0.1$currentTime, df_0.1$usedMemory, type = "l", col = "blue", xlab = "Tempo", ylab = "Memória Usada (MB)", main = "0.1")
plot(df_0.5$currentTime, df_0.5$usedMemory, type = "l", col = "red", xlab = "Tempo", ylab = "Memória Usada (MB)", main = "0.5")
plot(df_1$currentTime, df_1$usedMemory, type = "l", col = "green", xlab = "Tempo", ylab = "Memória Usada (MB)", main = "1")
plot(df_none$currentTime, df_none$usedMemory, type = "l", col = "purple", xlab = "Tempo", ylab = "Memória Usada (MB)", main = "Nenhum")

Questão 7
library(dplyr)
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
library(readr)
netflix_data <- read_csv("netflix_titles.csv")
## Rows: 7787 Columns: 12
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (11): show_id, type, title, director, cast, country, date_added, rating,...
## dbl (1): release_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.
netflix_one_country <- netflix_data %>%
filter(!grepl(",", country))
country_counts <- netflix_one_country %>%
count(country) %>%
arrange(desc(n)) %>%
slice_head(n = 10)
fig_pizza <- plot_ly(country_counts, labels = ~country, values = ~n, type = 'pie') %>%
layout(title = "Top 10 Países com Mais Conteúdos na Netflix em 2019")
fig_pizza
Questão 8
library(plotly)
fig_table <- plot_ly(
type = 'table',
header = list(
values = c('País', 'Total de Conteúdos'),
fill = list(color = 'gray'),
font = list(color = 'white', size = 14),
align = 'center'
),
cells = list(
values = list(country_counts$country, country_counts$n),
align = 'center'
)
) %>%
layout(title = 'Total de Conteúdos por País (Top 10)')
fig_table
Questão 9
netflix_data <- netflix_data %>%
mutate(decade = floor(release_year / 10) * 10)
content_by_decade <- netflix_data %>%
count(decade, type) %>%
arrange(decade)
fig_line <- plot_ly(content_by_decade, x = ~decade, y = ~n, color = ~type, type = 'scatter', mode = 'lines+markers',
colors = c('TV Show' = 'blue', 'Movie' = 'yellow')) %>%
layout(title = 'Quantidade de Conteúdo por Década na Netflix',
xaxis = list(title = 'Década'),
yaxis = list(title = 'Quantidade de Conteúdo'))
fig_line
Questão 10
library(plotly)
library(dplyr)
filtered_data <- netflix_data %>%
filter(type == 'Movie', release_year >= 2000, release_year <= 2010) %>%
mutate(genre = sapply(strsplit(listed_in, ", "), `[`, 1)) %>%
filter(genre %in% c('Dramas', 'Action & Adventure', 'Comedies'))
genre_counts <- filtered_data %>%
group_by(release_year, genre) %>%
tally() %>%
ungroup()
plot_ly(genre_counts, x = ~release_year, y = ~n, color = ~genre, type = 'bar', barmode = 'group') %>%
layout(title = "Quantidade de Filmes por Gênero (2000-2010)",
xaxis = list(title = 'Ano'),
yaxis = list(title = 'Quantidade de Filmes'))
## Warning: 'bar' objects don't have these attributes: 'barmode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'barmode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'barmode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'