Questões
Questão 1
# --- Dados fornecidos ---
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)
par(mfrow=c(4,2), mar=c(4,4,2,1))
layout(matrix(c(1,2,3,4,5,6), ncol=2, byrow=TRUE), heights = c(2,1,1,1,1,1))
plot(clock, MRT_1F, type="o", col="gold", pch=8, ylim=c(0,520),
xlab="Time between Things requests (seconds)", ylab="Response Time (sec.)",
main="(a) Mean Response Time vs Number of Fogs")
lines(clock, MRT_3F, type="o", col="orange", pch=6)
lines(clock, MRT_5F, type="o", col="magenta", pch=17)
lines(clock, MRT_10F, type="o", col="blue", pch=15)
lines(clock, MRT_15F, type="o", col="green", pch=4)
lines(clock, MRT_sem_F, type="o", col="black", pch=1)
legend("topright", legend=c("1 Fog","3 Fogs","5 Fogs","10 Fogs","15 Fogs","w/o Fog"),
col=c("gold","orange","magenta","blue","green","black"),
pch=c(8,6,17,15,4,1), bty="n")
barplot(rbind(MRT_sem_F, MRT_1F), beside=TRUE, names.arg=clock,
col=c("#E6E6E6","#666666"), log="y",
main="(b) 1 Fog vs w/o Fog",
xlab="Time between requests (s)", ylab="Response Time (s)")
legend("topright", legend=c("w/o Fog","1 Fog"), fill=c("#E6E6E6","#666666"), bty="n")
barplot(rbind(MRT_sem_F, MRT_3F), beside=TRUE, names.arg=clock,
col=c("#E6E6E6","#666666"), log="y",
main="(c) 3 Fogs vs w/o Fog",
xlab="Time between requests (s)", ylab="Response Time (s)")
legend("topright", legend=c("w/o Fog","3 Fogs"), fill=c("#E6E6E6","#666666"), bty="n")
barplot(rbind(MRT_sem_F, MRT_5F), beside=TRUE, names.arg=clock,
col=c("#E6E6E6","#666666"), log="y",
main="(d) 5 Fogs vs w/o Fog",
xlab="Time between requests (s)", ylab="Response Time (s)")
legend("topright", legend=c("w/o Fog","5 Fogs"), fill=c("#E6E6E6","#666666"), bty="n")
barplot(rbind(MRT_sem_F, MRT_10F), beside=TRUE, names.arg=clock,
col=c("#E6E6E6","#666666"), log="y",
main="(e) 10 Fogs vs w/o Fog",
xlab="Time between requests (s)", ylab="Response Time (s)")
legend("topright", legend=c("w/o Fog","10 Fogs"), fill=c("#E6E6E6","#666666"), bty="n")
barplot(rbind(MRT_sem_F, MRT_15F), beside=TRUE, names.arg=clock,
col=c("#E6E6E6","#666666"), log="y",
main="(f) 15 Fogs vs w/o Fog",
xlab="Time between requests (s)", ylab="Response Time (s)")
legend("topright", legend=c("w/o Fog","15 Fogs"), fill=c("#E6E6E6","#666666"), bty="n")

Questão 2
dados <- data.frame(
Quality_Rating = c("Good", "Very Good", "Excellent"),
`10-19` = c(53.8, 43.6, 2.6),
`20-29` = c(33.9, 54.2, 11.9),
`30-39` = c(2.6, 60.5, 36.8),
`40-49` = c(0.0, 21.4, 78.6)
)
dados_long <- pivot_longer(
dados,
cols = c(`X10.19`, `X20.29`, `X30.39`, `X40.49`),
names_to = "Meal_Price",
values_to = "Percentage"
)
ggplot(dados_long, aes(x = Meal_Price, y = Percentage, fill = Quality_Rating)) +
geom_bar(stat = "identity") +
labs(
title = "Qualidade da Refeição por Faixa de Preço",
x = "Faixa de Preço da Refeição (US$)",
y = "Percentual (%)",
fill = "Classificação de Qualidade"
) +
theme_minimal()

Questão 3
data("airquality")
maio <- subset(airquality, Month == 5)
maio$Temp_C <- (maio$Temp - 32) / 1.8
hist(maio$Temp_C,
main = "Histograma das Temperaturas de Maio (°C)",
xlab = "Temperatura (°C)",
ylab = "Frequência",
col = "lightblue",
border = "white",
prob = TRUE)
lines(density(maio$Temp_C), col = "red", lwd = 2)

Questão 4
sales <- read.table("https://training-course-material.com/images/8/8f/Sales.txt", header = TRUE)
total_vendas <- aggregate(sales$SALES, by = list(sales$COUNTRY), sum)
colnames(total_vendas) <- c("Country", "Total")
percent <- round(100 * total_vendas$Total / sum(total_vendas$Total), 1)
labels <- paste(total_vendas$Country, "-", percent, "%")
cores <- rainbow(length(labels))
pie(total_vendas$Total,
labels = labels,
col = cores,
main = "Distribuição Percentual das Vendas por País")
legend("topright", legend = total_vendas$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) # Remove os outliers

Questão 6
none <- read.csv("monitoringCloudData_NONE.csv", header = TRUE)
w01 <- read.csv("monitoringCloudData_0.1.csv", header = TRUE)
w05 <- read.csv("monitoringCloudData_0.5.csv", header = TRUE)
w1 <- read.csv("monitoringCloudData_1.csv", header = TRUE)
processa_dados <- function(df) {
df$currentTime <- as.POSIXct(df$currentTime, format = "%Y-%m-%d %H:%M:%S")
df$timeHour <- as.numeric(difftime(df$currentTime, df$currentTime[1], units = "hours"))
df$usedMemory <- as.character(df$usedMemory)
df$usedMemory <- gsub(",", "", df$usedMemory) # remover vírgulas se houver
df$usedMemoryMB <- ifelse(grepl("TB", df$usedMemory),
as.numeric(gsub("TB", "", df$usedMemory)) * 1000000,
ifelse(grepl("GB", df$usedMemory),
as.numeric(gsub("GB", "", df$usedMemory)) * 1024,
ifelse(grepl("MB", df$usedMemory),
as.numeric(gsub("MB", "", df$usedMemory)),
as.numeric(df$usedMemory))))
return(df)
}
none <- processa_dados(none)
w01 <- processa_dados(w01)
## Warning in ifelse(grepl("GB", df$usedMemory), as.numeric(gsub("GB", "", : NAs
## introduzidos por coerção
## Warning in ifelse(grepl("MB", df$usedMemory), as.numeric(gsub("MB", "", : NAs
## introduzidos por coerção
## Warning in ifelse(grepl("MB", df$usedMemory), as.numeric(gsub("MB", "", : NAs
## introduzidos por coerção
w05 <- processa_dados(w05)
## Warning in ifelse(grepl("GB", df$usedMemory), as.numeric(gsub("GB", "", : NAs
## introduzidos por coerção
## Warning in ifelse(grepl("GB", df$usedMemory), as.numeric(gsub("GB", "", : NAs
## introduzidos por coerção
## Warning in ifelse(grepl("GB", df$usedMemory), as.numeric(gsub("GB", "", : NAs
## introduzidos por coerção
w1 <- processa_dados(w1)
layout(matrix(1:4, nrow = 2, byrow = TRUE))
plot(none$timeHour, none$usedMemoryMB, type = "l", col = "black",
xlab = "Time (hour)", ylab = "Used Memory (MB)",
main = "Memory Analysis (None Workload)")
plot(w01$timeHour, w01$usedMemoryMB, type = "l", col = "blue",
xlab = "Time (hour)", ylab = "Used Memory (MB)",
main = "Memory Analysis (Workload of 0.1)")
plot(w05$timeHour, w05$usedMemoryMB, type = "l", col = "darkgreen",
xlab = "Time (hour)", ylab = "Used Memory (MB)",
main = "Memory Analysis (Workload of 0.5)")
plot(w1$timeHour, w1$usedMemoryMB, type = "l", col = "red",
xlab = "Time (hour)", ylab = "Used Memory (MB)",
main = "Memory Analysis (Workload of 1)")

Questão 7
netflix <- read.csv("Netflix_titles.csv", stringsAsFactors = FALSE)
netflix_filtrado <- netflix %>%
filter(!is.na(country)) %>%
mutate(country = trimws(country)) %>% # remove espaços extras
filter(country != "") %>% # remove strings vazias
filter(!grepl(",", country)) # mantém só 1 país
conteudos_pais <- netflix_filtrado %>%
group_by(country) %>%
summarise(total = n()) %>%
arrange(desc(total)) %>%
head(10)
fig_pizza <- plot_ly(
conteudos_pais,
labels = ~country,
values = ~total,
type = 'pie',
textinfo = 'label+percent',
insidetextorientation = 'radial'
) %>%
layout(
title = 'Top 10 Países com mais Conteúdos na Netflix (2019)',
showlegend = TRUE
)
fig_pizza
Questão 8
fig_tabela <- plot_ly(
type = 'table',
header = list(
values = c('País', 'Total de Conteúdos'),
fill = list(color = 'grey'),
font = list(color = 'white', size = 14),
align = 'center'
),
cells = list(
values = rbind(conteudos_pais$country, conteudos_pais$total),
align = 'center'
)
) %>%
layout(title = 'Tabela: Top 10 Países com Mais Conteúdos na Netflix')
fig_tabela
Questão 9
netflix <- read.csv("Netflix_titles.csv", stringsAsFactors = FALSE)
netflix <- netflix %>%
mutate(decada = floor(release_year / 10) * 10) %>%
filter(!is.na(decada))
dados_decada <- netflix %>%
group_by(decada, type) %>%
summarise(qtd = n(), .groups = 'drop')
fig_decada <- plot_ly(dados_decada, x = ~decada, y = ~qtd, color = ~type, colors = c("yellow", "blue"),
type = 'scatter', mode = 'lines+markers') %>%
layout(
title = "Quantidade de Conteúdos por Década",
xaxis = list(title = "Década"),
yaxis = list(title = "Qtd. Conteúdos"),
legend = list(title = list(text = "Tipo de Conteúdo"))
)
fig_decada
Questão 10
netflix <- read.csv("Netflix_titles.csv", stringsAsFactors = FALSE)
netflix_filmes <- netflix %>%
filter(type == "Movie", release_year >= 2000, release_year <= 2010)
netflix_filmes$genero_principal <- sapply(strsplit(netflix_filmes$listed_in, ","), `[`, 1)
netflix_filmes$genero_principal <- trimws(netflix_filmes$genero_principal)
generos <- c("Dramas", "Action & Adventure", "Comedies")
dados_genero <- netflix_filmes %>%
filter(genero_principal %in% generos) %>%
group_by(release_year, genero_principal) %>%
summarise(qtd = n(), .groups = 'drop')
fig_genero <- plot_ly(dados_genero,
x = ~release_year,
y = ~qtd,
color = ~genero_principal,
colors = c("blue", "orange", "green"),
type = 'bar') %>%
layout(
barmode = 'group',
title = 'Quantidade de Filmes por Gênero (2000–2010)',
xaxis = list(title = "Ano de Lançamento"),
yaxis = list(title = "Qtd. de Lançamentos"),
legend = list(title = list(text = "Gênero"))
)
fig_genero