Exercício 12 - Vizualização de dados

Tabset

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",
     xlab ="Time between Things requests (seconds)",
     ylab = "Response Time")

lines(clock,MRT_3F, type = "o",pch=11, col="yellow")
lines(clock,MRT_5F, type = "o", pch=1, col = "red")
lines(clock,MRT_10F, type = "o", pch=2,col = "blue" )
lines(clock,MRT_15F,type="o",pch=5,col = "purple")
lines(clock,MRT_sem_F,type="o",pch=4,col="green")
legend("topright",pch=c(4,11,1,2,5,4),col = c("black","yellow","red","blue","purple","green"),legend = c("MRT_1F","MRT_3F","MRT_5F","MRT_10F","MRT_15F","MRT_sem_F"))

comp1 <- rbind(MRT_sem_F,MRT_1F);
comp2 <- rbind(MRT_sem_F,MRT_3F);
comp3 <- rbind(MRT_sem_F,MRT_5F);
comp4 <- rbind(MRT_sem_F,MRT_10F);
comp5 <- rbind(MRT_sem_F,MRT_15F);

layout(mat= matrix(c(1,3,5,2,4,0), 
       nrow=3, 
       ncol=2))

barplot(comp1,beside =T, names.arg = clock,log = "y",
     col=c("#E6E6E6","#666666"),
     xlab ="Time between Things requests (seconds)",
     ylab = "Response Time(s)")
legend("topright",pch=c(15,15),col=c("#E6E6E6","#666666"), legend = c("w/o Fog","1 Fog"),cex = 0.8)

barplot(comp2,beside =T, names.arg = clock,log = "y",
     col=c("#E6E6E6","#666666"),
     xlab ="Time between Things requests",
     ylab = "Response Time(s)")
legend("topright",pch=c(15,15),col=c("#E6E6E6","#666666"), legend = c("w/o Fog","3 Fog"),cex = 0.8)

barplot(comp3,beside =T, names.arg = clock,log = "y",
     col=c("#E6E6E6","#666666"),
     xlab ="Time between Things requests",
     ylab = "Response Time(s)")
legend("topright",pch=c(15,15),col=c("#E6E6E6","#666666"), legend = c("w/o Fog","5 Fog"),cex = 0.8)

barplot(comp4,beside =T, names.arg = clock,log = "y",
     col=c("#E6E6E6","#666666"),
     xlab ="Time between Things requests",
     ylab = "Response Time(s)")
legend("topright",pch=c(15,15),col=c("#E6E6E6","#666666"), legend = c("w/o Fog","10 Fog"),cex = 0.8)

barplot(comp5,beside =T, names.arg = clock,log = "y",
     col=c("#E6E6E6","#666666"),
     xlab ="Time between Things requests",
     ylab = "Response Time(s)")
legend("topright",pch=c(15,15),col=c("#E6E6E6","#666666"), legend = c("w/o Fog","15 Fog"),cex = 0.8)

Questão 2

# Definir os dados simbólicos
qualidade <- c("Good", "Very good", "Excellent")
preco_10_19 <- c(30, 40, 30)
preco_20_29 <- c(20, 50, 30)
preco_30_39 <- c(10, 40, 50)
preco_40_49 <- c(5, 45, 50)

# Combinar os dados em uma matriz
dados <- rbind(preco_10_19, preco_20_29, preco_30_39, preco_40_49)
colnames(dados) <- qualidade
rownames(dados) <- c("$10-19", "$20-29", "$30-39", "$40-49")

# Criar o gráfico de barras empilhadas
barplot(t(dados),
        beside = FALSE,
        col = c("skyblue", "orange", "green"),
        legend.text = qualidade,
        args.legend = list(title = "Qualidade", x = "topright"),
        main = "Qualidade das Refeições por Categoria de Preço",
        xlab = "Categorias de Preço",
        ylab = "Percentual",
        ylim = c(0, 100))

Questão 3

data("airquality")
airquality$TempC <- (airquality$Temp - 32) / 1.8
temperaturas_maio <- airquality$TempC[airquality$Month == 5]
hist(temperaturas_maio,
     breaks = 10,
     col = "lightblue",
     main = "Temperaturas em Maio",
     xlab = "Temperatura (°C)",
     ylab = "Frequência",
     prob = TRUE)
lines(density(temperaturas_maio), col = "black", lwd = 3)

Questão 4

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

prop <- round(sales$SALES/sum(sales$SALES)*100)
lbls <- paste(sales$COUNTRY, prop)
lbls <- paste(lbls,"%",sep="")
pie(sales$SALES,lbls,main="Gráfico de pizza ", col=rainbow(4))

Questão 5

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

Questão 6

dados <- read.csv("C:/Users/Guilherme Henrique/Desktop/Faculdade/Mestrado/2024.1/CAD_24.1/Exercicios 12/monitoringCloudData_0.1.csv")
dados2 <- read.csv("C:/Users/Guilherme Henrique/Desktop/Faculdade/Mestrado/2024.1/CAD_24.1/Exercicios 12/monitoringCloudData_0.5.csv")
dados3 <- read.csv("C:/Users/Guilherme Henrique/Desktop/Faculdade/Mestrado/2024.1/CAD_24.1/Exercicios 12/monitoringCloudData_1.csv")
dados4 <- read.csv("C:/Users/Guilherme Henrique/Desktop/Faculdade/Mestrado/2024.1/CAD_24.1/Exercicios 12/monitoringCloudData_NONE.csv")

dados$currentTime <- as.POSIXct(dados$currentTime)
dados$currentTime_horas <- as.numeric(format(dados$currentTime, "%H"))

dados$usedMemory <- as.numeric(gsub("[[:alpha:]]", "", dados$usedMemory)) * ifelse(grepl("GB", dados$usedMemory), 1024, 1)

diferenca_horas <- difftime(dados$currentTime[2], dados$currentTime[1], units = "hours")


layout(mat= matrix(c(1,2,3,4), 
       nrow=2, 
       ncol=2))

plot(dados$currentTime,dados$usedMemory, type="l",
     xlab = "Time(hour)",
     ylab = "USED MEMORY (MB)",
     main = "Memory Analysis (Workload of 0.1)",
     cex.axis = 1,
     cex.lab = 0.8)

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
netflix <- read.csv("C:/Users/Guilherme Henrique/Desktop/Faculdade/Mestrado/2024.1/CAD_24.1/Exercicios 12/netflix_titles.csv")

netflix_single <- netflix  %>%   filter(!grepl(",", country) & country != "")

country1 <- netflix_single %>% group_by(country) %>% summarise(count = n()) %>%arrange(desc(count)) %>%slice(1:10)

fig <- plot_ly(country1, labels = ~country, values = ~count, type = 'pie') 

fig

Questão 8

fig1 <- plot_ly(
  type = 'table',
  header = list(
    values = c("País", "Total de conteúdos"),
    fill = list(color = 'gray'),
    font = list(color = 'white'),
    align = 'center'
  ),
  cells = list(
    values = list(country1$country, country1$count),
    align = 'center'
  )
) %>%
  layout(title = 'Top 10 Países de filmes da Netflix em 2019')
fig1

Questão 9

netflix <- netflix %>% mutate(decade = floor(release_year / 10) * 10)
content_by_decade <- netflix %>% group_by(decade, type) %>% summarise(count = n()) %>% filter(decade >= 1940 & decade <= 2020)
## `summarise()` has grouped output by 'decade'. You can override using the
## `.groups` argument.
movies_by_decade <- content_by_decade %>%
  filter(type == "Movie")

tv_shows_by_decade <- content_by_decade %>%
  filter(type == "TV Show")

fig2 <- plot_ly() %>%
  add_trace(
    x = movies_by_decade$decade,
    y = movies_by_decade$count,
    type = 'scatter',
    mode = 'lines+markers',
    name = 'Filmes',
    line = list(color = 'yellow')
  ) %>%
  add_trace(
    x = tv_shows_by_decade$decade,
    y = tv_shows_by_decade$count,
    type = 'scatter',
    mode = 'lines+markers',
    name = 'Séries',
    line = list(color = 'blue')
  ) %>%
  layout(
    title = 'Quantidade de Conteúdo por Década no Netflix',
    xaxis = list(title = 'Década'),
    yaxis = list(title = 'Quantidade de Conteúdo'),
    legend = list(x = 0.1, y = 0.9)
  )

fig2

Questão 10

netflix_filtered <- netflix %>%
  filter(release_year >= 2000 & release_year <= 2010 & type == "Movie") %>%
  mutate(main_genre = sapply(strsplit(as.character(listed_in), ", "), `[`, 1)) %>%
  filter(main_genre %in% c("Dramas", "Action & Adventure", "Comedies"))
genre_counts <- netflix_filtered %>%
  group_by(release_year, main_genre) %>%
  summarise(count = n()) %>%
  ungroup()
## `summarise()` has grouped output by 'release_year'. You can override using the
## `.groups` argument.
fig3 <- plot_ly(
  data = genre_counts,
  x = ~release_year,
  y = ~count,
  color = ~main_genre,
  type = 'bar',
  barmode = 'group',
  colors = c('Dramas' = 'red', 'Action & Adventure' = 'blue', 'Comedies' = 'green')
) %>%
  layout(
    title = 'Quantidade de Filmes por Gênero (2000-2010)',
    xaxis = list(title = 'Ano'),
    yaxis = list(title = 'Quantidade de Filmes'),
    barmode = 'group'
  )

fig3
## Warning: 'bar' objects don't have these attributes: 'barmode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'barmode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'barmode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'