# Dados
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)
# Criando gráfico de linha
series_data <- list(
MRT_1F, MRT_3F, MRT_5F, MRT_10F, MRT_15F, MRT_sem_F
)
legend_labels <- c("1 Fog", "3 Fogs", "5 Fogs", "10 Fogs", "15 Fogs", "wo Fog")
plot_colors <- c("black", "yellow", "red", "blue", "purple", "green")
plot_pch <- c(4, 6, 2, 5, 17, 3)
plot(clock, series_data[[1]],
type = "o",
pch = plot_pch[1],
col = plot_colors[1],
lwd = 1,
ylim = c(0, 550),
xlim = c(0, 3.1),
axes = FALSE,
xlab = "Time between Things requests (seconds)",
ylab = "Response Time (sec.)",
main = "")
for (i in 2:length(series_data)) {
lines(clock, series_data[[i]],
type = "o",
pch = plot_pch[i],
col = plot_colors[i],
lwd = 1)
}
axis(1, at = seq(0, 3, by = 0.5))
axis(2, at = seq(0, 500, by = 100), las = 1)
box()
legend("topright",
legend = legend_labels,
col = plot_colors,
pch = plot_pch,
lty = 1,
lwd = 1,
bty = "o",
cex = 0.8,
inset = c(0.01, 0.01))
# Dados
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)
# Criando gráficos de barras
df_barras <- data.frame(
Time = clock,
`1 Fog` = MRT_1F,
`3 Fogs` = MRT_3F,
`5 Fogs` = MRT_5F,
`10 Fogs` = MRT_10F,
`15 Fogs` = MRT_15F,
`w/o Fog` = MRT_sem_F,
check.names = FALSE
)
fogs_cols <- c("1 Fog", "3 Fogs", "5 Fogs", "10 Fogs", "15 Fogs")
x_labels <- as.character(clock)
cor_sem_fog <- "#E6E6E6"
cor_com_fog <- "#666666"
old_par <- par(no.readonly = TRUE)
par(mfrow = c(3, 2), mar = c(4, 4, 1, 1) + 0.1, mgp = c(2.5, 0.7, 0))
for (i in 1:length(fogs_cols)) {
fog_col_name <- fogs_cols[i]
data_to_plot <- rbind(
df_barras[["w/o Fog"]],
df_barras[[fog_col_name]]
)
bar_colors <- c(cor_sem_fog, cor_com_fog)
bar_centers <- barplot(data_to_plot,
beside = TRUE,
log = "y",
col = bar_colors,
names.arg = x_labels,
ylim = c(0.1, 550),
main = "",
xlab = "Time between Things requests",
ylab = "Response time (s)",
xaxt = "n",
yaxt = "n",
border = "black"
)
log_breaks <- c(0.2, 0.5, 1, 5, 50, 500)
axis(2, at = log_breaks, labels = log_breaks, las = 1)
axis(1, at = colMeans(bar_centers), labels = x_labels, cex.axis = 0.8)
legend("topright",
legend = c("w/o Fog", fog_col_name),
fill = bar_colors,
bty = "o",
cex = 0.8,
border = "black"
)
}
par(old_par)
# Dados
dados_matriz <- matrix(
c(53.8, 43.6, 2.6,
33.9, 54.2, 11.9,
2.6, 60.5, 36.8,
0.0, 21.4, 78.6),
nrow = 3,
ncol = 4,
byrow = FALSE,
dimnames = list(
c("Good", "Very Good", "Excellent"),
c("$10–19", "$20–29", "$30–39", "$40–49")
)
)
cores_ratings <- c("lightblue", "gray", "tomato")
old_par <- par(no.readonly = TRUE)
par(mar = c(5, 4, 6, 2) + 0.1)
# Criando o gráfico
barplot(dados_matriz,
main = "Qualidade da Refeição por Categoria de Preço",
xlab = "Preço da Refeição (Meal Price)",
ylab = "Porcentagem (%)",
col = cores_ratings,
border = "black",
ylim = c(0, 100),
las = 1
)
legend("topright",
legend = rownames(dados_matriz),
fill = cores_ratings,
title = "Avaliação de Qualidade (Quality Rating)",
cex = 0.8,
bty = "o",
xpd = TRUE,
inset = c(-0.02, -0.05)
)
# Dados
data(airquality)
maio_data_temp <- airquality$Temp[airquality$Month == 5]
temp_celsius <- (maio_data_temp - 32) / 1.8
# Criando o gráfico
hist_results <- hist(temp_celsius,
freq = FALSE,
main = "Distribuição de Temperatura (Maio) em Nova York",
xlab = "Temperatura (°C)",
ylab = "Densidade",
col = "#ADD8E6",
border = "black",
breaks = 7,
ylim = c(0, 0.25)
)
densidade_calculada <- density(temp_celsius, na.rm = TRUE)
lines(densidade_calculada,
col = "red",
lwd = 2
)
# Dados
sales <- read.table("https://training-course-material.com/images/8/8f/Sales.txt", header = TRUE)
vendas_por_pais <- aggregate(SALES ~ COUNTRY, data = sales, FUN = sum)
total_global <- sum(vendas_por_pais$SALES)
vendas_por_pais$Percentage <- (vendas_por_pais$SALES / total_global) * 100
pie_labels <- paste(
round(vendas_por_pais$Percentage, 1),
"%",
sep = ""
)
pie_colors <- rainbow(nrow(vendas_por_pais))
# Criando o gráfico
old_par <- par(no.readonly = TRUE)
par(mar = c(1, 1, 3, 10), xpd = TRUE)
pie(vendas_por_pais$SALES,
labels = pie_labels,
col = pie_colors,
main = "Total de Vendas por País"
)
legend("right",
legend = vendas_por_pais$COUNTRY,
fill = pie_colors,
title = "País",
cex = 0.8,
bty = "n",
inset = c(-0.1, 0)
)
boxplot_colors <- "yellow"
# Criando o gráfico
boxplot(count ~ spray,
data = InsectSprays,
main = "Contagem de Insetos por Tipo de Inseticida (Outliers Removidos)",
xlab = "Tipo de Inseticida (Spray)",
ylab = "Contagem de Insetos",
col = boxplot_colors,
border = "black",
outline = FALSE,
notch = FALSE,
las = 1
)
# Dados
base_path <- "C:/Users/alexa/Downloads/monitoringCloudData/"
files_to_process <- c("monitoringCloudData_NONE.csv",
"monitoringCloudData_0.1.csv",
"monitoringCloudData_0.5.csv",
"monitoringCloudData_1.csv")
labels <- c("None Workload", "Workload of 0.1", "Workload of 0.5", "Workload of 1.0")
convert_to_mb <- function(memory_str) {
if (is.na(memory_str) || memory_str == "") {
return(NA)
}
value <- as.numeric(gsub("(\\s*[A-Za-z]+)", "", memory_str))
unit <- toupper(gsub("([^A-Za-z])", "", memory_str))
if (is.na(value)) {
return(NA)
}
conversion_factor <- 1
if (unit == "GB") {
conversion_factor <- 1024
} else if (unit == "TB") {
conversion_factor <- 1000000
} else if (unit != "MB") {
conversion_factor <- 1
}
return(value * conversion_factor)
}
process_data <- function(file_name) {
full_path <- paste0(base_path, file_name)
df <- read.csv(full_path,
stringsAsFactors = FALSE,
na.strings = c("NA", ""),
sep = ","
)
df$usedMemory_MB <- sapply(df$usedMemory, convert_to_mb)
df$currentTime <- as.POSIXct(df$currentTime, format="%Y-%m-%d %H:%M:%OS")
start_time <- min(df$currentTime, na.rm = TRUE)
df$Time_Hours <- as.numeric(difftime(df$currentTime, start_time, units = "hours"))
return(df[!is.na(df$usedMemory_MB), ])
}
# Criando os gráficos
old_par <- par(no.readonly = TRUE)
par(mfrow = c(2, 2),
mar = c(4, 4, 3, 1) + 0.1,
mgp = c(2.5, 0.7, 0)
)
for (i in 1:length(files_to_process)) {
file <- files_to_process[i]
label <- labels[i]
df_plot <- tryCatch({
process_data(file)
}, error = function(e) {
message(paste("Erro ao processar o arquivo", file, ":", e$message))
return(NULL)
})
if (is.null(df_plot)) {
next
}
plot(df_plot$Time_Hours, df_plot$usedMemory_MB,
type = "l",
col = "black",
lwd = 1,
main = paste("Memory Analysis (", label, ")", sep = ""),
xlab = "Time (hour)",
ylab = "Used Memory (MB)",
xlim = c(0, max(df_plot$Time_Hours, na.rm = TRUE)),
ylim = c(min(df_plot$usedMemory_MB, na.rm = TRUE), max(df_plot$usedMemory_MB, na.rm = TRUE))
)
grid(nx = NULL, ny = NULL, col = "lightgray", lty = 3)
}
library(readr)
library(dplyr)
library(plotly)
netflix_path <- "C:/Users/alexa/Downloads/netflix_titles.csv"
# Dados
netflix_data <- tryCatch({
read_csv(netflix_path)
}, error = function(e) {
message(paste("Erro ao carregar o arquivo:", e$message))
message("Verifique se o caminho do arquivo está correto e se o arquivo existe.")
return(NULL)
})
if (is.null(netflix_data)) {
stop("O processamento foi interrompido devido ao erro no carregamento do arquivo.")
}
netflix_filtered <- netflix_data %>%
filter(!is.na(country) & !grepl(",", country))
top_10_countries <- netflix_filtered %>%
group_by(country) %>%
summarise(count = n()) %>%
ungroup() %>%
arrange(desc(count)) %>%
slice_head(n = 10)
# Criando o gráfico
fig <- plot_ly(top_10_countries,
labels = ~country,
values = ~count,
type = 'pie',
textinfo = 'percent',
insidetextfont = list(color = '#FFFFFF'),
hoverinfo = 'label+percent+value',
marker = list(line = list(color = '#FFFFFF', width = 1)),
sort = FALSE
) %>%
layout(title = list(text = 'Top 10 Países com Maior Conteúdo na Netflix (Conteúdo de País Único)',
font = list(size = 14)),
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
fig
library(readr)
library(dplyr)
library(plotly)
netflix_path <- "C:/Users/alexa/Downloads/netflix_titles.csv"
# Dados
netflix_data <- tryCatch({
read_csv(netflix_path)
}, error = function(e) {
stop("Erro: Não foi possível carregar o arquivo. Verifique o caminho.")
})
netflix_filtered <- netflix_data %>%
filter(!is.na(country) & !grepl(",", country))
top_10_countries <- netflix_filtered %>%
group_by(country) %>%
summarise(count = n()) %>%
ungroup() %>%
arrange(desc(count)) %>%
slice_head(n = 10)
table_data <- top_10_countries %>%
rename(País = country, `Total de conteúdos` = count)
header_fill_color <- 'rgb(128, 128, 128)'
header_font_color <- 'rgb(255, 255, 255)'
alignment <- 'center'
# Criando a tabela
fig_table <- plot_ly(
type = 'table',
header = list(
values = c("País", "Total de conteúdos"),
line = list(width = 1, color = 'black'),
fill = list(color = header_fill_color),
align = alignment,
font = list(color = header_font_color, size = 12)
),
cells = list(
values = list(table_data$País, table_data$`Total de conteúdos`),
line = list(color = 'black', width = 1),
fill = list(color = c('white')),
align = alignment,
font = list(size = 11)
)
) %>%
layout(title = "Top 10 Países por Conteúdo Único na Netflix")
fig_table
library(plotly)
caminho_dataset <- "C:/Users/alexa/Downloads/netflix_titles.csv"
netflix <- read.csv(caminho_dataset, stringsAsFactors = FALSE)
# Dados
netflix$decade <- floor(netflix$release_year / 10) * 10
netflix_filtrado <- netflix[netflix$type %in% c("Movie", "TV Show"), ]
contagem_tabela <- as.data.frame(table(netflix_filtrado$decade, netflix_filtrado$type),
stringsAsFactors = FALSE)
names(contagem_tabela) <- c("decade", "type", "count")
contagem_tabela$decade <- as.numeric(contagem_tabela$decade)
decadas_completas <- seq(from = min(contagem_tabela$decade),
to = max(contagem_tabela$decade),
by = 10)
tipos_conteudo <- c("Movie", "TV Show")
base_completa <- expand.grid(decade = decadas_completas,
type = tipos_conteudo)
final_data <- merge(base_completa, contagem_tabela,
by = c("decade", "type"),
all.x = TRUE)
final_data$count[is.na(final_data$count)] <- 0
# Criando o gráfico
p <- plot_ly()
p <- add_trace(
p,
data = final_data[final_data$type == "TV Show", ],
x = ~decade,
y = ~count,
type = 'scatter',
mode = 'lines+markers',
line = list(color = '#1f77b4'),
marker = list(color = '#1f77b4'),
name = 'TV Series'
)
p <- add_trace(
p,
data = final_data[final_data$type == "Movie", ],
x = ~decade,
y = ~count,
type = 'scatter',
mode = 'lines+markers',
line = list(color = '#ff7f0e'),
marker = list(color = '#ff7f0e'),
name = 'Movies'
)
p <- layout(
p,
xaxis = list(
title = "Década",
tickvals = decadas_completas[decadas_completas %% 20 == 0],
tickmode = "array"
),
yaxis = list(
title = "Qnd. Conteúdo",
rangemode = "tozero"
),
legend = list(
x = 0.9,
y = 1
)
)
p
library(plotly)
caminho_dataset <- "C:/Users/alexa/Downloads/netflix_titles.csv"
netflix <- read.csv(caminho_dataset, stringsAsFactors = FALSE)
# Dados
filmes <- netflix[netflix$type == "Movie", ]
filmes$genero_principal <- sapply(filmes$listed_in, function(x) {
primeiro_genero <- strsplit(x, split = ",")[[1]][1]
return(trimws(primeiro_genero))
})
filmes$genero_principal[filmes$genero_principal == "Dramas"] <- "Drama"
filmes$genero_principal[filmes$genero_principal == "Action & Adventure"] <- "Ação e Aventura"
filmes$genero_principal[filmes$genero_principal == "Comedies"] <- "Comédia"
generos_interesse <- c("Drama", "Ação e Aventura", "Comédia")
ano_min <- 2001
ano_max <- 2009
dados_filtrados <- filmes[
filmes$release_year >= ano_min &
filmes$release_year <= ano_max &
filmes$genero_principal %in% generos_interesse,
]
contagem_tabela <- as.data.frame(table(dados_filtrados$release_year, dados_filtrados$genero_principal),
stringsAsFactors = FALSE)
names(contagem_tabela) <- c("Ano", "Genero", "count")
contagem_tabela$Ano <- as.numeric(contagem_tabela$Ano)
anos_completos <- seq(from = ano_min, to = ano_max, by = 1)
base_completa <- expand.grid(Ano = anos_completos, Genero = generos_interesse)
final_data <- merge(base_completa, contagem_tabela,
by = c("Ano", "Genero"),
all.x = TRUE)
final_data$count[is.na(final_data$count)] <- 0
# Criando o gráfico
cores_genero <- c("Drama" = "#1f77b4", "Ação e Aventura" = "#ff7f0e", "Comédia" = "#2ca02c")
p <- plot_ly(
data = final_data,
x = ~Ano,
y = ~count,
color = ~Genero,
type = 'bar',
colors = cores_genero,
name = ~Genero
) %>%
layout(
barmode = 'group',
xaxis = list(
title = "Ano de Lançamento",
tickmode = "array",
tickvals = final_data$Ano,
dtick = 1
),
yaxis = list(
title = "Qnt. de Lançamentos",
rangemode = "tozero"
),
legend = list(
x = 0.8,
y = 1
)
)
p