Respostas
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)
plot(clock, MRT_1F, type = "o", pch = 4, col = "black", lwd = 2,
xlab = "Time between Things requests (seconds)",
ylab = "Response Time (sec.)",
ylim = c(0, 550))
lines(clock, MRT_3F, type = "o", pch = 17, col = "orange", lwd = 2)
lines(clock, MRT_5F, type = "o", pch = 15, col = "yellow", lwd = 2)
lines(clock, MRT_10F, type = "o", pch = 2, col = "blue", lwd = 2)
lines(clock, MRT_15F, type = "o", pch = 0, col = "purple", lwd = 2)
lines(clock, MRT_sem_F, type = "o", pch = 8, col = "green", lwd = 2)
legend("topright",
legend = c("1 Fog", "3 Fogs", "5 Fogs", "10 Fogs", "15 Fogs", "w/o Fog"),
col = c("black", "orange", "yellow", "blue", "purple", "green"),
pch = c(4, 17, 15, 2, 0, 8),
lty = 1,
cex = 0.8)

par(mfrow = c(3, 2))
plot_fog <- function(y_values, title) {
barplot(rbind(MRT_sem_F, y_values),
beside = TRUE,
names.arg = clock,
col = c("#E6E6E6", "#666666"),
log = "y",
ylim = c(0.1, max(MRT_sem_F, y_values)*1.5),
xlab = "Time between Things requests",
ylab = "Response time (s)")
legend("topright",
inset = c(-0.1, -0.3),
xpd = TRUE,
legend = c("w/o Fog", title),
fill = c("#E6E6E6", "#666666"),
bty = "n")
}
plot_fog(MRT_1F, "1 Fog")
plot_fog(MRT_3F, "3 Fogs")
plot_fog(MRT_5F, "5 Fogs")
plot_fog(MRT_10F, "10 Fogs")
plot_fog(MRT_15F, "15 Fogs")

Questão 2
good <- c(53.8, 33.9, 2.6, 0.0)
veryGood <- c(43.6, 54.2, 60.5, 21.4)
excellent <- c(2.6, 11.9, 36.8, 78.6)
data_matrix <- matrix(c(
good,
veryGood,
excellent
), nrow = 3, ncol=4, byrow = TRUE)
category <- c("$10-19", "$20-29", "$30-39", "$40-49")
colors <- c("red", "green", "blue")
barplot(data_matrix, col = colors, names.arg = category,
xlab = "Prices", ylab = "Quality Rating")
legend("topright", pch = c(15,15,15), legend = c("good", "very good", "excellent"), col= colors)

Questão 3
airquality$TempC <- (airquality$Temp - 32) / 1.8
maio <- subset(airquality, Month == 5)
hist(
maio$TempC,
main = "Histograma das Temperaturas em Maio (°C)",
xlab = "temperatura (°C)",
ylab = "frequência",
col = "lightgreen",
border = "white",
freq = FALSE
)
lines(density(maio$TempC, na.rm = TRUE),
col = "black",
lwd = 2)

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

Questão 5
outlier_filter <- function(x) {
Q1 <- quantile(x, 0.25)
Q3 <- quantile(x, 0.75)
IQR_value <- IQR(x)
return(x[x >= (Q1 - 1.5 * IQR_value) & x <= (Q3 + 1.5 * IQR_value)])
}
clean_data <- tapply(InsectSprays$count, InsectSprays$spray, outlier_filter)
clean_data_df <- data.frame(
count = unlist(clean_data),
spray = rep(names(clean_data), sapply(clean_data, length))
)
boxplot(count ~ spray, data = clean_data_df,
col = "yellow",
main = "Contagem de Insetos por Tipo de Inseticida",
xlab = "Tipo de Inseticida",
ylab = "Contagem de Insetos")

Questão 7
netflix_country <- netflix[grep(",", netflix$country, invert = TRUE), ]
order_country <- netflix_country %>% group_by(country) %>% summarise( Content = sum(length(title), ma.rm = TRUE )) %>% arrange(desc(Content))
order_country <- slice(filter(order_country, !(is.na(country))), 1:10)
plot_ly(
order_country,
labels=~country,
values=~Content,
type = 'pie'
)
Questão 8
plot_ly(
type = 'table',
header = list(
values = c("País", "Total de conteúdos"),
align = c("center", "center"),
line = list(width = 1, color = "black"),
fill = list(color = "grey"),
font = list(color = "white")
),
cells = list(
values = rbind(order_country$country, order_country$Content),
align = c("center", "center"),
line = list(color = "black", width = 1),
font = list(color = c("black"))
)
)
Questão 9
decadas <- netflix %>%
mutate(decade = floor(release_year / 10) * 10) %>%
group_by(decade, type) %>%
summarise(quantity = n())
## `summarise()` has grouped output by 'decade'. You can override using the
## `.groups` argument.
series <- filter(decadas, type != "Movie")
movies <- filter(decadas, type == "Movie")
line <- plot_ly(
data = data.frame(series),
x= ~decade,
y= ~quantity,
type = "scatter",
mode = "lines+markers",
line = list(color = "blue"),
name = "TV Series"
)
line <- line %>% add_trace(
data = data.frame(movies),
x= ~decade,
y= ~quantity,
type = "scatter",
mode = "lines+markers",
line = list(color = "orange"),
name = "Movies"
)
line <- line %>% layout(
xaxis = list(title = "Década"),
yaxis = list(title = "Qnd.Conteúdo")
)
line