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)
# Gráfico
plot(clock, MRT_1F, type="o", col="black", pch=4, lty=1,
ylim=c(0, 520), xlab="Time between Things requests (seconds)",
ylab="Response Time (sec.)")
lines(clock, MRT_3F, type="o", col="gold", pch=5)
lines(clock, MRT_5F, type="o", col="red", pch=6)
lines(clock, MRT_10F, type="o", col="blue", pch=2)
lines(clock, MRT_15F, type="o", col="purple", pch=17)
lines(clock, MRT_sem_F, type="o", col="green", pch=8)
legend("topright",
legend=c("1 Fog","3 Fogs","5 Fogs","10 Fogs","15 Fogs","w/o Fog"),
col=c("black","gold","red","blue","purple","green"),
pch=c(4,5,6,2,17,8),
lty=1,
cex=0.8)
title(main="Mean Response Time (MRT) vs Clock Interval")

# Lista de datasets
fog_list <- list(MRT_1F, MRT_3F, MRT_5F, MRT_10F, MRT_15F)
fog_labels <- c("1 Fog", "3 Fogs", "5 Fogs", "10 Fogs", "15 Fogs")
par(mfrow=c(3,2), mar=c(4,4,2,2))
for (i in 1:5) {
barplot(
rbind(MRT_sem_F, fog_list[[i]]),
beside=TRUE, log="y", names.arg=clock,
col=c("#E6E6E6", "#666666"), border="black",
ylim=c(0.1, 1000),
ylab="Response time (s)",
xlab="Time between Things requests",
main=paste("w/o Fog vs", fog_labels[i])
)
legend("topright", legend=c("w/o Fog", fog_labels[i]),
fill=c("#E6E6E6", "#666666"), border="black", cex=0.8)
}
plot.new()

Questão 2
qualidade <- matrix(c(15, 20, 25, 10, 5,
10, 15, 20, 30, 25),
nrow=2, byrow=TRUE)
colnames(qualidade) <- c("Muito Ruim", "Ruim", "Média", "Boa", "Excelente")
rownames(qualidade) <- c("Barato", "Caro")
barplot(qualidade, beside=FALSE, col=c("skyblue", "orange"),
main="Qualidade por Categoria de Preço",
xlab="Classificação", ylab="Quantidade")
legend("topright", legend=rownames(qualidade), fill=c("skyblue","orange"))

Questão 3
data("airquality")
temp_C <- (airquality$Temp - 32) / 1.8
hist(temp_C, breaks=10, col="lightgreen",
main="Temperaturas em °C (Maio)",
xlab="Temperatura (°C)", ylab="Frequência", freq=FALSE)
lines(density(temp_C, 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)
total_sales <- aggregate(sales$SALES ~ sales$COUNTRY, FUN=sum)
percent <- round(100 * total_sales$`sales$SALES` / sum(total_sales$`sales$SALES`), 1)
pie(total_sales$`sales$SALES`,
labels=paste0(total_sales$`sales$COUNTRY`, " (", percent, "%)"),
main="Total de Vendas por País",
col=rainbow(length(percent)))
legend("topright", legend=total_sales$`sales$COUNTRY`, fill=rainbow(length(percent)))

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

Questão 6
# ---- NONE ----
df_none <- read_csv("monitoringCloudData_NONE.csv", show_col_types = FALSE)
df_none$currentTime <- as.POSIXct(df_none$currentTime)
x <- toupper(str_trim(df_none$usedMemory))
num <- suppressWarnings(as.numeric(str_extract(x, "[0-9]+\\.?[0-9]*")))
df_none$usedMemory_MB <- ifelse(str_detect(x, "TB"), num * 1e6,
ifelse(str_detect(x, "GB"), num * 1024,
ifelse(str_detect(x, "KB"), num / 1024,
ifelse(str_detect(x, "B"), num / (1024 * 1024),
ifelse(str_detect(x, "MB"), num, num)))))
# Tempo contínuo em horas
df_none$time_hour <- as.numeric(difftime(df_none$currentTime, min(df_none$currentTime), units = "hours"))
# ---- 0.1 ----
df_01 <- read_csv("monitoringCloudData_0.1.csv", show_col_types = FALSE)
df_01$currentTime <- as.POSIXct(df_01$currentTime)
x <- toupper(str_trim(df_01$usedMemory))
num <- suppressWarnings(as.numeric(str_extract(x, "[0-9]+\\.?[0-9]*")))
df_01$usedMemory_MB <- ifelse(str_detect(x, "TB"), num * 1e6,
ifelse(str_detect(x, "GB"), num * 1024,
ifelse(str_detect(x, "KB"), num / 1024,
ifelse(str_detect(x, "B"), num / (1024 * 1024),
ifelse(str_detect(x, "MB"), num, num)))))
df_01$time_hour <- as.numeric(difftime(df_01$currentTime, min(df_01$currentTime), units = "hours"))
# ---- 0.5 ----
df_05 <- read_csv("monitoringCloudData_0.5.csv", show_col_types = FALSE)
df_05$currentTime <- as.POSIXct(df_05$currentTime)
x <- toupper(str_trim(df_05$usedMemory))
num <- suppressWarnings(as.numeric(str_extract(x, "[0-9]+\\.?[0-9]*")))
df_05$usedMemory_MB <- ifelse(str_detect(x, "TB"), num * 1e6,
ifelse(str_detect(x, "GB"), num * 1024,
ifelse(str_detect(x, "KB"), num / 1024,
ifelse(str_detect(x, "B"), num / (1024 * 1024),
ifelse(str_detect(x, "MB"), num, num)))))
df_05$time_hour <- as.numeric(difftime(df_05$currentTime, min(df_05$currentTime), units = "hours"))
# ---- 1.0 ----
df_1 <- read_csv("monitoringCloudData_1.csv", show_col_types = FALSE)
df_1$currentTime <- as.POSIXct(df_1$currentTime)
x <- toupper(str_trim(df_1$usedMemory))
num <- suppressWarnings(as.numeric(str_extract(x, "[0-9]+\\.?[0-9]*")))
df_1$usedMemory_MB <- ifelse(str_detect(x, "TB"), num * 1e6,
ifelse(str_detect(x, "GB"), num * 1024,
ifelse(str_detect(x, "KB"), num / 1024,
ifelse(str_detect(x, "B"), num / (1024 * 1024),
ifelse(str_detect(x, "MB"), num, num)))))
df_1$time_hour <- as.numeric(difftime(df_1$currentTime, min(df_1$currentTime), units = "hours"))
# --- Layout de gráficos ---
layout(matrix(1:4, nrow = 2, byrow = TRUE))
# --- Gráficos individuais ---
plot(df_none$time_hour, df_none$usedMemory_MB, type = "l", col = "black",
main = "Memory Analysis (None Workload)",
xlab = "Time (hour)", ylab = "Used Memory (MB)")
plot(df_01$time_hour, df_01$usedMemory_MB, type = "l", col = "black",
main = "Memory Analysis (Workload of 0.1)",
xlab = "Time (hour)", ylab = "Used Memory (MB)")
plot(df_05$time_hour, df_05$usedMemory_MB, type = "l", col = "black",
main = "Memory Analysis (Workload of 0.5)",
xlab = "Time (hour)", ylab = "Used Memory (MB)")
plot(df_1$time_hour, df_1$usedMemory_MB, type = "l", col = "black",
main = "Memory Analysis (Workload of 1.0)",
xlab = "Time (hour)", ylab = "Used Memory (MB)")

Questão 7
netflix <- read_csv("netflix_titles.csv", show_col_types = FALSE)
netflix_clean <- netflix %>%
filter(!is.na(country)) %>%
filter(!str_detect(country, ",")) %>%
count(country, sort=TRUE) %>%
top_n(10, n)
plot_ly(netflix_clean, labels=~country, values=~n, type="pie") %>%
layout(title="10 Países com Mais Conteúdos na Netflix")
Questão 8
plot_ly(
type = 'table',
header = list(
values = c("País", "Total de Conteúdos"),
fill_color = 'white',
line_color = 'gray',
align = 'center',
font = list(color = 'Black', size = 14)
),
cells = list(
values = list(netflix_clean$country, netflix_clean$n),
align = 'center',
fill_color = 'white',
line_color = 'gray'
)
)
Questão 9
netflix$decade <- floor(netflix$release_year / 10) * 10
conteudos <- netflix %>%
filter(!is.na(release_year)) %>%
group_by(decade, type) %>%
summarise(qtd=n(), .groups='drop')
plot_ly(conteudos, x=~decade, y=~qtd, color=~type, colors=c("blue", "yellow"),
type='scatter', mode='lines+markers') %>%
layout(title="Conteúdos por Década",
xaxis=list(title="Década"), yaxis=list(title="Quantidade"))
Questão 10
# Mantendo apenas os anos de 2000 a 2010
netflix_2000_2010 <- netflix %>%
filter(release_year >= 2000 & release_year <= 2010)
# Mantendo apenas o primeiro gênero listado
netflix_2000_2010 <- netflix_2000_2010 %>%
mutate(listed_in = str_trim(str_split_fixed(listed_in, ",", 2)[, 1]))
# Filtrando os gêneros de interesse
genres_selected <- c("Dramas", "Action & Adventure", "Comedies")
data_genres <- netflix_2000_2010 %>%
filter(listed_in %in% genres_selected) %>%
group_by(release_year, listed_in) %>%
summarise(total = n(), .groups = "drop")
# Gráfico de barras lado a lado (Plotly)
plot <- plot_ly(
data_genres,
x = ~release_year,
y = ~total,
color = ~listed_in,
colors = c("gold", "skyblue", "orange"),
type = "bar"
) %>%
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"))
)
plot