Bibliotecas

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(plotly)
## 
## Attaching package: 'plotly'
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following object is masked from 'package:graphics':
## 
##     layout
library(dplyr)

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,
     xlab="EixoX", ylab="EixoY",
     main="Gráfico simples")
lines(clock, MRT_3F, type="o", col="yellow", pch=11)
lines(clock, MRT_5F, type="o", col="red")
lines(clock, MRT_10F, type="o", col="blue", pch=2)
lines(clock, MRT_15F, type="o", col="purple", pch=5)
lines(clock, MRT_sem_F, type="o", col="green", pch=4)
legend("topright", pch=c(4, 11, 1, 2, 5, 4),
       col=c("black", "yellow", "red", "blue", "purple", "green"),
       legend=c("1 Fog", "3 Fogs", "5 Fogs", "10 Fogs", "15 Fogs", "w/o Fogs"))

barplot(matrix(c(MRT_sem_F, MRT_1F), nrow=2, ncol=7, byrow=T), col=c("#E6E6E6", "#666666"),
        xlab="Time between Things requests", ylab = "Response time(s)" , beside=T)
legend("topright", col=c("#E6E6E6", "#666666"), pch=c(15,15), legend=c("w/o Fogs", "1 Fog"))

barplot(matrix(c(MRT_sem_F, MRT_3F), nrow=2, ncol=7, byrow=T), col=c("#E6E6E6", "#666666"),
        xlab="Time between Things requests", ylab = "Response time(s)" , beside=T)
legend("topright", col=c("#E6E6E6", "#666666"), pch=c(15,15), legend=c("w/o Fogs", "3 Fogs"))

barplot(matrix(c(MRT_sem_F, MRT_5F), nrow=2, ncol=7, byrow=T), col=c("#E6E6E6", "#666666"),
        xlab="Time between Things requests", ylab = "Response time(s)" , beside=T)
legend("topright", col=c("#E6E6E6", "#666666"), pch=c(15,15), legend=c("w/o Fogs", "5 Fogs"))

barplot(matrix(c(MRT_sem_F, MRT_10F), nrow=2, ncol=7, byrow=T), col=c("#E6E6E6", "#666666"),
        xlab="Time between Things requests", ylab = "Response time(s)" , beside=T)
legend("topright", col=c("#E6E6E6", "#666666"), pch=c(15,15), legend=c("w/o Fogs", "10 Fogs"))

barplot(matrix(c(MRT_sem_F, MRT_15F), nrow=2, ncol=7, byrow=T), col=c("#E6E6E6", "#666666"),
        xlab="Time between Things requests", ylab = "Response time(s)" , beside=T)
legend("topright", col=c("#E6E6E6", "#666666"), pch=c(15,15), legend=c("w/o Fogs", "15 Fogs"))

Questão 2

data <- matrix(
  c(53.8, 33.9, 2.6, 0, 43.6, 54.2, 60.5, 21.4, 2.6, 11.9, 36.8, 78.6),
  nrow = 3,
  byrow = TRUE
)

barplot(
  data,
  col = c("#E6E6E6", "#666666", "#B3B3B3"),
  legend.text = rownames(data),
  args.legend = list(x = "topleft", bty = "n"),
  xlab = "Meal Price",
  ylab = "Quality Rating",
)

legend("topright", col=c("#E6E6E6", "#666666", "#B3B3B3"), pch=c(15,15,15),
       legend=c("Good", "Very Good", "Excellent"))

Questão 3

data(airquality)

temp_maio <- airquality[airquality$Month == 5, "Temp"]

temp_maio_C <- (temp_maio - 32) / 1.8


hist(
  temp_maio_C,
  col = "grey",
  probability = T,
  main = "Histogram of Temperature",
  xlab = "Temperature (°C)",
  ylab = "Density"
)

lines(density(temp_maio_C), col = "red")

Questão 4

sales <- read.table("https://training-course-material.com/images/8/8f/Sales.txt", header = TRUE)

pct <- round(sales$SALES/sum(sales$SALES)*100)
lbls <- paste(sales$COUNTRY, pct)
lbls <- paste(lbls, "%", sep="")

pie(sales$SALES, labels = lbls,
    main = "Sales by Country",
    col=rainbow(nrow(sales)))

legend("topright", legend = sales$COUNTRY,
       fill = rainbow(nrow(sales)), bty = "n")

Questão 5

data(InsectSprays)

boxplot(count ~ spray, data = InsectSprays,
        col = "yellow", outline = FALSE,
        xlab = "Spray", ylab = "Count")

Questão 7

conteudo <- read.csv("https://www.dropbox.com/s/bso7ierg8oyjjun/netflix_titles.csv?dl=1")

conteudo_unico_pais <- conteudo %>%
  filter(country != "") %>%
  filter(!str_detect(country, ","))

conteudo_por_pais <- conteudo_unico_pais %>%
  group_by(country) %>%
  summarize(count = n()) %>%
  arrange(desc(count))

top_10_paises <- conteudo_por_pais %>%
  head(10)

plot_ly(
  data = top_10_paises,
  labels = ~country,
  values = ~count,
  type = "pie"
)

Questão 8

conteudo_unico_pais <- conteudo %>%
  filter(country != "") %>%
  filter(!str_detect(country, ","))

conteudo_por_pais <- conteudo_unico_pais %>%
  group_by(country) %>%
  summarize(count = n()) %>%
  arrange(desc(count))

top_10_paises <- conteudo_por_pais %>%
  head(10)

plot_ly(
  type = "table",
  header = list(
    values = c("País", "Total de conteúdos"),
    align = c("center", "center"),
    line = list(width = 1.5, color = "black"),
    fill = list(color = "grey"),
    font = list(family = "Arial", size = 12, color = c("white"))
  ),
  cells = list(
    values = rbind(top_10_paises$country, top_10_paises$count),
    align = c("center", "center"),
    line = list(width = 1.5, color = "black"),
    font = list(family = "Arial", size = 12, color=c("black"))
  )
)