Questão 1
# Dados fornecidos
clock <- c(0.1, 0.5, 1, 1.5, 2, 2.5, 3)
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)
# Organiza os vetores em uma lista para fácil iteração
MRT_list <- list(MRT_1F, MRT_3F, MRT_5F, MRT_10F, MRT_15F, MRT_sem_F)
names(MRT_list) <- c("1 Fog", "3 Fogs", "5 Fogs", "10 Fogs", "15 Fogs", "w/o Fog")
cores <- c("black", "yellow", "red", "blue", "purple", "green")
plot(clock, MRT_1F, type="o", col="black", pch=4, ylim=c(0, max(MRT_1F)),
xlab="Clock", ylab="Tempo de Resposta", main="Gráfico de Linha")# x
# Outras curvas com símbolos desejados
lines(clock, MRT_3F, type="o", col="yellow", pch=11) # Estrela de Davi
lines(clock, MRT_5F, type="o", col="red", pch=1) # Cículo
lines(clock, MRT_10F, type="o", col="blue", pch=2) # Triângulo
# Exemplo adicional
lines(clock, MRT_15F, type="o", col="purple", pch=5) # Losango
lines(clock, MRT_sem_F, type="o", col="green", pch=4) # X
# Legenda com os mesmos símbolos
legend("topright",
legend=c("1 Fog", "3 Fogs", "5 Fogs", "10 Fogs",
"15 Fogs", "w/o Fog"),
col=c("black", "yellow", "red", "blue", "purple", "green"),
pch=c(4, 11, 1, 2, 5, 4), lty=1, cex=0.8)

#graficos-barras-ajustados, fig.width=10, fig.height=9
# Layout 3 linhas x 2 colunas
layout(matrix(c(1, 2, 3, 4, 5, 0), nrow = 3, byrow = TRUE))
par(mar = c(4, 4, 1, 1)) # Margens menores, sem título
# Função auxiliar para gerar cada gráfico
plot_barras <- function(withFog, noFog, main_label) {
barplot(
rbind(noFog, withFog),
beside = TRUE,
log = "y",
col = c("#E6E6E6", "#666666"),
names.arg = clock,
xlab = "Time between Things requests",
ylab = "Response time (s)",
cex.axis = 0.75,
cex.lab = 0.85,
cex.names = 0.9
)
legend("topright", legend = c("w/o Fog", main_label),
fill = c("#E6E6E6", "#666666"), cex = 0.8)
}
# Gráficos
plot_barras(MRT_1F, MRT_sem_F, "1 Fog")
plot_barras(MRT_3F, MRT_sem_F, "3 Fogs")
plot_barras(MRT_5F, MRT_sem_F, "5 Fogs")
plot_barras(MRT_10F, MRT_sem_F, "10 Fogs")
plot_barras(MRT_15F, MRT_sem_F, "15 Fogs")

Questão 2
knitr::include_graphics("I:/Meu Drive/Desktop/Mestrado/R/tabela.png")

# Criar a matriz com os dados (% em decimal)
dados <- matrix(c(
53.8, 43.6, 2.6, # $10–19
33.9, 54.2, 11.9, # $20–29
2.6, 60.5, 36.8, # $30–39
0.0, 21.4, 78.6 # $40–49
),
nrow = 3, byrow = FALSE)
# Nome das categorias (linhas = qualidade, colunas = preço)
rownames(dados) <- c("Good", "Very Good", "Excellent")
colnames(dados) <- c("$10–19", "$20–29", "$30–39", "$40–49")
# Cores para as faixas
cores <- c("skyblue", "lightgreen", "orange")
# Cria o gráfico empilhado
barplot(dados,
beside = FALSE,
col = cores,
ylim = c(0, 120),
main = "Classificação de Qualidade por Faixa de Preço",
xlab = "Faixa de Preço",
ylab = "Porcentagem (%)",
legend.text = rownames(dados),
args.legend = list(x = "topright"))

Questão 6
setwd("I://Meu Drive//Desktop//Mestrado//R//monitoringCloudData (1)")
library(stringr)
layout(matrix(c(1,2,3,4), nrow = 2, byrow = TRUE))
arquivos <- list(
"NONE" = read.csv("monitoringCloudData_NONE.csv"),
"0.1" = read.csv("monitoringCloudData_0.1.csv"),
"0.5" = read.csv("monitoringCloudData_0.5.csv"),
"1.0" = read.csv("monitoringCloudData_1.csv")
)
titulos <- c(
"Memory Analysis (None Workload)",
"Memory Analysis (Workload of 0.1)",
"Memory Analysis (Workload of 0.5)",
"Memory Analysis (Workload of 1.0)"
)
indice <- 1
for (nome in names(arquivos)) {
df <- arquivos[[nome]]
# Corrige formato do tempo
df$currentTime <- as.POSIXct(df$currentTime)
tempo_horas <- as.numeric(difftime(df$currentTime, min(df$currentTime), units = "hours"))
# Extrai valor e unidade da coluna usedMemory
df$valor <- as.numeric(str_extract(df$usedMemory, "[0-9.]+"))
unidade <- toupper(trimws(str_extract(df$usedMemory, "[A-Za-z]+")))
# Aplica fator de conversão para megabytes
fator <- ifelse(unidade == "TB", 1e6,
ifelse(unidade == "GB", 1024,
ifelse(unidade == "MB", 1, NA)))
# Aplica conversão e remove linhas com erro
df$mem_MB <- df$valor * fator
df <- df[!is.na(df$mem_MB) & !is.na(tempo_horas), ]
# Plot
plot(tempo_horas[1:nrow(df)], df$mem_MB, type = "l",
main = titulos[indice],
xlab = "Time (hour)",
ylab = "Used Memory (MB)")
indice <- indice + 1
}
