R Markdown - Ecercício 12

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)

plot(MRT_1F, type="o", pch="x", cex=1, col="black",
     xlab="Timme betweens Things requests (seconds)",ylab="Response Time(sec.)")

lines(MRT_3F, type="o", pch="@", cex=1, col="yellow" )
lines(MRT_5F, type="o", pch="o", cex=1, col="red" )
lines(MRT_10F, type="o", pch="*", cex=1, col="blue" )
lines(MRT_15F, type="o", pch="&", cex=1, col="purple" )
lines(MRT_sem_F, type="o", pch="x", cex=1, col="green" )

legend("topright",pch=c("x","@","o","*","&","x"),col=c("black","yellow","red","blue","purple","green"),legend=c("1 Fog", "3 Fogs","5 Fogs","10 Fogs", "15 Fogs","w/o Fog"))

par(mfrow = c(3, 2))
barplot(rbind(MRT_sem_F, MRT_1F), beside = TRUE, 
        col = c("#E6E6E6", "#666666"),
        ylab = "Response Time(sec.)", 
        xlab = "Timme betweens Things requests (seconds)",
        names.arg = c(0.1,0.5,1,1.5,2,2.5,3))

legend("topright",pch=c(15,15),col=c("#E6E6E6", "#666666"),legend=c("w/o Fog","1 Fog"))

barplot(rbind(MRT_sem_F, MRT_3F), beside = TRUE, 
        col = c("#E6E6E6", "#666666"),
        ylab = "Response Time(sec.)", 
        xlab = "Timme betweens Things requests (seconds)",
        names.arg = c(0.1,0.5,1,1.5,2,2.5,3))

legend("topright",pch=c(15,15),col=c("#E6E6E6", "#666666"),legend=c("w/o Fog","1 Fog"))

barplot(rbind(MRT_sem_F, MRT_5F), beside = TRUE, 
        col = c("#E6E6E6", "#666666"),
        ylab = "Response Time(sec.)", 
        xlab = "Timme betweens Things requests (seconds)",
        names.arg = c(0.1,0.5,1,1.5,2,2.5,3))

legend("topright",pch=c(15,15),col=c("#E6E6E6", "#666666"),legend=c("w/o Fog","1 Fog"))

barplot(rbind(MRT_sem_F, MRT_10F), beside = TRUE, 
        col = c("#E6E6E6", "#666666"),
        ylab = "Response Time(sec.)", 
        xlab = "Timme betweens Things requests (seconds)",
        names.arg = c(0.1,0.5,1,1.5,2,2.5,3))

legend("topright",pch=c(15,15),col=c("#E6E6E6", "#666666"),legend=c("w/o Fog","1 Fog"))

barplot(rbind(MRT_sem_F, MRT_15F), beside = TRUE, 
        col = c("#E6E6E6", "#666666"),
        ylab = "Response Time(sec.)", 
        xlab = "Timme betweens Things requests (seconds)",
        names.arg = c(0.1,0.5,1,1.5,2,2.5,3))

legend("topright",pch=c(15,15),col=c("#E6E6E6", "#666666"),legend=c("w/o Fog","1 Fog"))

Questão 2

excellent <- c(2.6,11.9,36.8,78.6)
very_good <- c(43.6,54.2,60.5,21.4)
good <- c(53.8,33.9,2.6,0.0)

posicoes <- barplot(rbind(good, very_good, excellent), beside = FALSE, col = c("blue", "green", "yellow"),
                    main="Quality Rating by Meal Price",
                    ylab = "Meal percent",
                    xlab = "Meal Price",
                    names.arg = c("$10-19", "$20-29", "$30-39", "$40-49"),
                    legend.text = c("Good", "Very Good", "Excellent"),
                    args.legend = list(x = "topright", bty = "n"))

Questão 3

data(airquality)
dados_maio <- airquality[airquality$Month == 5, ]
dados_maio$Temp_Celsius <- (dados_maio$Temp - 32) / 1.8

hist(dados_maio$Temp_Celsius, 
     col = "grey",
     main = "Histograma de Temperaturas de Maio",
     xlab = "Temperatura em°C",
     ylab = "Frequência",
     probability = TRUE)

lines(density(dados_maio$Temp_Celsius), col = "red", lwd = 2)
legend("topright", legend = "Densidade", col = "red", lwd = 2)

Questão 4

Sem acesso ao dataset. ## Questão 5

data(InsectSprays)

boxplot(count ~ spray, data = InsectSprays, outline = FALSE, col = "yellow",
        main = "Contagens de Insetos",
        xlab = "Tipo de Inseticida", ylab = "Contagem de Insetos")

## Questão 6 #não consegui fazer

Questão 7

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(plotly)
## Carregando pacotes exigidos: ggplot2
## 
## 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(stringr)

netflix_data <- read.csv("C:/Users/yansi/Downloads/netflix_titles.csv")
netflix_data_filtered <- netflix_data %>%
  filter(!is.na(country)) %>%
  filter(str_count(country, ",") == 0)

country_counts <- netflix_data_filtered %>%
  group_by(country) %>%
  summarise(content_count = n()) %>%
  arrange(desc(content_count))

top_countries <- head(country_counts, 10)

plot_ly(
  labels = top_countries$country,
  values = top_countries$content_count,
  type = "pie"
) %>%
  layout(title = "Top 10 Países com mais conteúdo na Netflix",
         showlegend = TRUE)

Questão 8

plot_ly(
  type = "table",
  header = list(
    values = c("País", "Total de conteúdos"),
    align = "center",
    fill = list(color = "grey"),
    font = list(family = "Arial", size = 12, color = "white")
  ),
  cells = list(
    values = list(top_countries$country, top_countries$content_count),
    align = c("center", "center"),
    fill = list(color = c("#F5F8FF", "#F5F8FF"))
  )
) %>%
  layout(
    title = "Top 10 Países com Mais Conteúdo na Netflix",
    margin = list(l = 0, r = 0, t = 0, b = 0)
  )

Questão 9

netflix_data_filtered <- netflix_data %>%
  filter(!is.na(release_year))

netflix_data_filtered <- netflix_data_filtered %>%
  mutate(decade = 10 * (release_year %/% 10))

content_by_decade <- netflix_data_filtered %>%
  group_by(decade, type) %>%
  summarise(content_count = n(), .groups = 'drop')

plot_ly(content_by_decade, x = ~decade, y = ~content_count,
                     color = ~type, type = "scatter", mode = "lines+markers") %>%
  layout(title = "Quantidade de conteúdo por década na Netflix",
         xaxis = list(title = "Década"),
         yaxis = list(title = "Qnt. de Conteúdo"))
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels

## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels

Questão 10

movies_2000_2010 <- netflix_data %>%
  filter(type == "Movie", between(release_year, 2000, 2010))

movies_2000_2010 <- movies_2000_2010 %>%
  mutate(genre = str_extract(listed_in, "^[^,]+"))

selected_genres <- c("Dramas", "Action & Adventure", "Comedies")
movies_selected_genres <- movies_2000_2010 %>%
  filter(genre %in% selected_genres)

movies_count_by_genre <- movies_selected_genres %>%
  group_by(release_year, genre) %>%
  summarise(movie_count = n(), .groups = 'drop')

plot_ly(movies_count_by_genre, x = ~release_year, y = ~movie_count,
                    color = ~genre, type = "bar",
                    colors = c("Dramas" = "blue", "Action & Adventure" = "orange", "Comedies" = "green")) %>%
  layout(title = "Qnt. de filmes por gênero entre 2000 e 2010",
         xaxis = list(title = "Ano"),
         yaxis = list(title = "Quantidade de Filmes"))