Questões

Questao 1: Graficos (R Base)

clock <- c(0.1, 0.5, 1, 1.5, 2, 2.5, 3)

MRT_1F <-c(517.1468,85.1309,30.3332,12.6947,3.3041,1.1823,1.1892)
MRT_3F <-c(156.6893,11.5408,0.4512,0.4509,0.4502,0.4496,0.4543)

layout(matrix(c(1,2), nrow=1))
plot(clock, MRT_1F, type="b", col="blue", pch=19,
     main="Questao 1 - MRT (1F)", xlab="Clock (GHz)", ylab="MRT (ms)")

barplot(rbind(MRT_1F, MRT_3F), beside=TRUE, log="y",
        col=c("#E6E6E6","#666666"),
        names.arg=clock, main="Questao 1 - Comparacao MRT", ylab="log(MRT)")
legend("topright", legend=c("1F","3F"), fill=c("#E6E6E6","#666666"))

Questao 2: Grafico de Barras Empilhadas

refeicao <- data.frame(
  Preco = c("Barato","Moderado","Caro"),
  Ruim = c(10,5,2),
  Boa = c(20,25,10),
  Excelente = c(5,15,30)
)

barplot(as.matrix(refeicao[,2:4]), beside=FALSE, col=c("red","yellow","green"),
        names.arg=refeicao$Preco, main="Questao 2 - Qualidade da Refeicao",
        xlab="Categoria de Preco", ylab="Quantidade")
legend("topright", fill=c("red","yellow","green"),
       legend=c("Ruim","Boa","Excelente"))

Questao 3: Histograma com curva de densidade

data(airquality)
tempC <- (airquality$Temp - 32) / 1.8

hist(tempC, col="lightblue", probability=TRUE,
     main="Questao 3 - Histograma de Temperaturas (C)",
     xlab="Temperatura (C)")
lines(density(tempC), col="red", lwd=2)

Questao 5: Boxplot sem Outliers

data(InsectSprays)

boxplot(InsectSprays$count ~ InsectSprays$spray,
        col="yellow", main="Questao 5 - Contagem de insetos por inseticida",
        ylab="Contagem", outline=FALSE)

Questao 6: Monitoramento Cloud

arquivos <- c("monitoringCloudData_0.1.csv",
              "monitoringCloudData_0.5.csv",
              "monitoringCloudData_1.csv",
              "monitoringCloudData_NONE.csv")

layout(matrix(1:4, nrow=2, byrow=TRUE))

for (arq in arquivos){

  dados <- read.csv(arq)

  dados$currentTime <- as.POSIXct(dados$currentTime)

  # CORREÇÃO: precisa de double escape \\.
  valores <- as.numeric(gsub("[^0-9\\.]", "", dados$usedMemory))
  unidade <- toupper(gsub("[0-9\\.]", "", dados$usedMemory))

  dados$usedMemory_MB <- dplyr::case_when(
    unidade == "GB" ~ valores * 1024,
    unidade == "TB" ~ valores * 1024 * 1024,
    unidade == "MB" ~ valores,
    unidade == "B"  ~ valores / (1024 * 1024),
    TRUE            ~ NA_real_
  )

  dados <- dados[!is.na(dados$usedMemory_MB), ]

  plot(dados$currentTime, dados$usedMemory_MB,
       type="l", col="blue", main=paste("Questao 6 -", arq),
       xlab="Tempo", ylab="Memoria (MB)")
}

Questao 7: Pizza (Plotly)

netflix <- read.csv("netflix_titles.csv")

pizza <- netflix %>%
  filter(!grepl(",", country)) %>%
  count(country, sort=TRUE) %>%
  head(10)

plot_ly(pizza, labels=~country, values=~n, type="pie") %>%
  layout(title="Questao 7 - Top 10 paises (conteudo Netflix)")

Questao 8: Tabela (Plotly)

plot_ly(
  type='table',
  header=list(values=c("Pais", "Total de conteudos"),
              fill=list(color="grey"),
              font=list(color="white")),
  cells=list(values=list(pizza$country, pizza$n),
             align="center")
)

Questao 9: Conteudo por decada (Plotly)

netflix$decade <- floor(netflix$release_year/10)*10

series <- netflix %>% filter(type=="TV Show") %>% count(decade)
filmes <- netflix %>% filter(type=="Movie") %>% count(decade)

plot_ly(series, x=~decade, y=~n, type='scatter', mode='lines',
        name="Series", line=list(color='blue')) %>%
  add_trace(data=filmes, x=~decade, y=~n,
            name="Filmes", line=list(color='yellow')) %>%
  layout(title="Questao 9 - Conteudos por decada")

Questao 10: Filmes por genero (Plotly)

generos <- netflix %>%
  filter(type=="Movie") %>%
  filter(release_year >= 2000 & release_year <= 2010) %>%
  mutate(primary = sub(",.*","", listed_in)) %>%
  filter(primary %in% c("Dramas","Action & Adventure","Comedies")) %>%
  count(release_year, primary)

plot_ly(generos, x=~release_year, y=~n, color=~primary,
        type="bar", barmode="group") %>%
  layout(title="Questao 10 - Filmes por genero (2000–2010)",
         xaxis=list(title="Ano"),
         yaxis=list(title="Quantidade"))
## 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'