library(stringr)
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)
## Loading required package: 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(readr)
library(tidyr)
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="Time beetween things requests (seconds)", ylab="Response Time (sec.)", )
lines(clock, MRT_3F, type="o", pch=13, 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")
fog_names <- c("1 Fog", "3 Fog", "5 Fog","10 Fog","15 Fog","W/O Fog")
legend("topright", pch = c(4,13,1,2,5,4),
col = c("black","yellow","red","blue", "purple", "green"),
legend = fog_names)

fogs <- list(MRT_1F, MRT_3F, MRT_5F, MRT_10F, MRT_15F)
layout(matrix(c(1:6), nrow=3, byrow=TRUE))
for (i in 1:length(fogs)) {
df <- data.frame(clock)
df <- data.frame(matrix(ncol = length(clock), nrow = 0))
colnames(df) <- clock
df[1, ] <- MRT_sem_F
df[2, ] <- fogs[[i]]
row.names(df) <- c("w/o Fog", fog_names[i])
barplot((as.matrix(df)), col=c("#E6E6E6", "#666666"), beside=T)
legend("topright", fill = c("#E6E6E6", "#666666"), legend = row.names(df))
}





2
df <- data.frame(
b = c(53.8, 43.6, 2.6), j = c(33.9, 54.2, 11.9), r = c(2.6,60.5,36.8), c = c(0,21.4,78.6),
row.names = c("Good", "Very Good", "Excelent")
)
barplot((as.matrix(df)), names.arg=c("$10-19","$20-29","$30-39", "$40-49"),col=rainbow(6))

3
data <- airquality[airquality$Month == 5, ]
transf <- (data$Temp-32)/1.8
hist(transf,xlab="Temperatura em °C",ylab="Densidade",
main="Temperatura no mês de Maio",density = 25,
col='blue', probability = T)
den <- density(transf)
lines(den)

4
data <- read.table("https://training-course-material.com/images/8/8f/Sales.txt",header=TRUE)
sales <- read.table("https://training-course-material.com/images/8/8f/Sales.txt",header=TRUE)
pct_legend <- round(sales$SALES/sum(sales$SALES)*100)
lbls <- paste(pct_legend, "%", sep="")
sales <- data$SALES
pie(sales, labels = lbls, main = "% VENDAS P/PAIS", col = rainbow(6))
legend("topright", legend = pct_legend, cex = 0.8, fill = rainbow(6))

5
insets <- InsectSprays
boxplot(count ~ spray, data = insets, xlab="TIPO",
ylab="INSETO",main="INSETOS P/ SPRAY", outline=FALSE, col="yellow")

6
cloud_none <- read.csv("monitoringCloudData_NONE.csv", header = T)
cloud_0.1 <- read.csv("monitoringCloudData_0.1.csv", header = T)
cloud_0.5 <- read.csv("monitoringCloudData_0.5.csv", header = T)
cloud_1.0 <- read.csv("monitoringCloudData_1.csv", header = T)
analyses <- list(cloud_none, cloud_0.1, cloud_0.5, cloud_1.0)
headers <- c("None", "0.1", "0.5", "1.0")
layout(matrix(c(1:4), nrow=2, byrow=TRUE))
convert_to_mb <- function(x){
num <- as.numeric(sub("(\\d*(.\\d+)*)(.*)", "\\1", x))
num * unname(c("MB"=1, "GB"=1024)[sub("(\\d*(.\\d+)*)(.*)", "\\3", x)])
}
for (i in 1:length(analyses)) {
data<- analyses[[i]]
data$currentTime <- as.POSIXct(data$currentTime)
plot(as.numeric(data$currentTime - min(data$currentTime), units="hours"), convert_to_mb(data$usedMemory), type="l", xlab="Used memory (MB)", ylab="Time (hour)",
main= paste("Memory analysis (Workload of ", headers[i], ")", collapse=""))
}

7
data <- read.csv('netflix_titles.csv')
by_country <- data[!grepl(pattern=',', x=data$country),] %>%
group_by(country) %>%
summarise(conteudos=n())
by_country <- head(arrange(by_country,desc(conteudos)), 10)
plot_ly(by_country,
type='pie',
labels=~country,
values=~conteudos)
8
plot_ly(type = 'table',
columnwidth = c(10, 10),
columnorder = c(0, 1),
header = list(
values = c("PAIS","TOTAL"),
align = c("center", "center")
),
cells = list(values = rbind(by_country$country,by_country$conteudos), align = c("center", "center")))
10
data$Genero <- sapply(X=data$listed_in, FUN=function(x){unlist(strsplit(x, split=','))[1]})
data <- data %>%
filter((Genero=='Dramas' | Genero=='Action & Adventure' | Genero=='Comedies') & (release_year > 2000 & release_year < 2010)) %>%
group_by(release_year, Genero) %>%
summarise(quantidade=n())
## `summarise()` has grouped output by 'release_year'. You can override using the
## `.groups` argument.
fig <- plot_ly(data = data,
x=~unique(release_year)
)
fig <- fig %>%
add_trace(y=~filter(data,Genero=='Dramas')$quantidade,
type='bar',
name='Drama')
fig <- fig %>%
add_trace(y=~filter(data,Genero=='Action & Adventure')$quantidade,
type='bar',
name='Ação e Aventura')
fig <- fig %>%
add_trace(y=~filter(data,Genero=='Comedies')$quantidade,
type='bar',
name='Comédia')
fig <- fig %>%
layout(xaxis=list(title='Ano de Lançamento'),
yaxis=list(title='Qnt. de lançamentos'))
fig