Questões

Questão 1

# Dados
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)

# Layout 
par(mar=c(1, 3, 1, 1))
layout(matrix(c(1, 1), nrow=1, ncol=2))

# Gráfico de Linhas
plot(clock, MRT_1F, type="l", col="red", xlab="Clock (GHz)", ylab="MRT", ylim=c(0, max(MRT_1F, MRT_3F, MRT_5F, MRT_10F, MRT_15F, MRT_sem_F)))
lines(clock, MRT_3F, type="l", col="blue")
lines(clock, MRT_5F, type="l", col="green")
lines(clock, MRT_10F, type="l", col="purple")
lines(clock, MRT_15F, type="l", col="orange")
lines(clock, MRT_sem_F, type="l", col="brown")

# Legenda
legend("topright", legend=c("MRT_1F", "MRT_3F", "MRT_5F", "MRT_10F", "MRT_15F", "MRT_sem_F"), 
       col=c("red", "blue", "green", "purple", "orange", "brown"), 
       lty=1, cex=0.8)

# Organiza os dados
data_matrix <- rbind(MRT_1F, MRT_sem_F, MRT_3F, MRT_sem_F, MRT_5F, MRT_sem_F, MRT_10F, MRT_sem_F, MRT_15F, MRT_sem_F)

# Gráfico de Barras e Legendas
barplot(data_matrix[c(1,2),], beside=TRUE, col=c("#666666", "#E6E6E6"), log="y", names.arg=clock, xlab="Clock (GHz)", ylab="MRT_1F", main="MRT_1F")
legend("topright", legend=c("MRT_1F", "MRT_sem_F"), fill=c("#666666", "#E6E6E6"))

barplot(data_matrix[c(3,4),], beside=TRUE, col=c("#666666", "#E6E6E6"), log="y", names.arg=clock, xlab="Clock (GHz)", ylab="MRT_3F", main="MRT_3F")
legend("topright", legend=c("MRT_3F", "MRT_sem_F"), fill=c("#666666", "#E6E6E6"))

barplot(data_matrix[c(5,6),], beside=TRUE, col=c("#666666", "#E6E6E6"), log="y", names.arg=clock, xlab="Clock (GHz)", ylab="MRT_5F", main="MRT_5F")
legend("topright", legend=c("MRT_5F", "MRT_sem_F"), fill=c("#666666", "#E6E6E6"))

barplot(data_matrix[c(7,8),], beside=TRUE, col=c("#666666", "#E6E6E6"), log="y", names.arg=clock, xlab="Clock (GHz)", ylab="MRT_10F", main="MRT_10F")
legend("topright", legend=c("MRT_10F", "MRT_sem_F"), fill=c("#666666", "#E6E6E6"))

barplot(data_matrix[c(9,10),], beside=TRUE, col=c("#666666", "#E6E6E6"), log="y", names.arg=clock, xlab="Clock (GHz)", ylab="MRT_15F", main="MRT_15F")
legend("topright", legend=c("MRT_15F", "MRT_sem_F"), fill=c("#666666", "#E6E6E6"))

### Questão 2

# Dados 
Quality_Rating <- c("Good", "Very Good", "Excellent")
Meal_Price <- matrix(c(53.8, 43.6, 2.6,
                       33.9, 54.2, 11.9,
                       2.6, 60.5, 36.8,
                       0.0, 21.4, 78.6),
                     nrow=3, ncol=4)

colnames(Meal_Price) <- c("$10-19", "$20-29", "$30-39", "$40-49")
rownames(Meal_Price) <- Quality_Rating

# Gráfico de Barras Empilhadas e legenda
barplot(Meal_Price, beside=FALSE, col=c("orange", "red", "purple"),
        legend.text=c("Good", "Very Good", "Excellent"), args.legend=list(x="topright", bty="n", inset=c(-0.0, -0.3)),
        main="Meal Price by Quality Rating", xlab="Meal Price", ylab="Percentage")

### Questão 3

# Carregar o dataset airquality
data("airquality")

# Filtrar apenas os dados de maio
may_data <- subset(airquality, Month == 5)

# Converter as temperaturas de Fahrenheit para Celsius
may_data$Temp_Celsius <- (may_data$Temp - 32) / 1.8

# Gerar o histograma das temperaturas em Celsius
hist(may_data$Temp_Celsius,
     main = "Histograma das Temperaturas em Maio (°C)",
     xlab = "Temperatura (°C)",
     ylab = "Frequência",
     col = "grey",
     border = "black",
     probability = TRUE)

# Adicionar a curva de densidade
lines(density(may_data$Temp_Celsius), col = "green", lwd = 2)

### Questão 4

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

# Verificar as colunas 
str(sales)
## 'data.frame':    6 obs. of  2 variables:
##  $ COUNTRY: chr  "US" "UK" "France" "Poland" ...
##  $ SALES  : int  340 290 510 820 120 780
if ("SALES" %in% colnames(sales)) {
  sales_sum <- aggregate(sales$SALES, by = list(sales$COUNTRY), FUN = sum)
} else {
  stop("Nenhuma coluna encontrada.")
}

# Renomear as colunas
names(sales_sum) <- c("Country", "TotalSales")
sales_sum$Percentage <- round(100 * sales_sum$TotalSales / sum(sales_sum$TotalSales), 1)

# Gráfico de pizza
pie(sales_sum$TotalSales, 
    labels = paste(sales_sum$Country, sales_sum$Percentage, "%"), 
    col = rainbow(length(sales_sum$Country)), 
    main = "Porcentagem de Vendas por País")

# Legenda
legend("topright", 
       legend = sales_sum$Country, 
       fill = rainbow(length(sales_sum$Country)))

### Questão 5

# Dataset
data("InsectSprays")

# Criar o boxplot amarelo
boxplot(count ~ spray, data = InsectSprays, 
        main = "Boxplot das Contagens de Insetos por Tipo de Inseticida", 
        xlab = "Tipo de Inseticida", 
        ylab = "Contagem de Insetos", 
        col = "yellow",
        outline = FALSE)