library(readr)
library(dplyr)
##
## Adjuntando el paquete: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
bebidas <- read_csv("bebidas.csv")
## Rows: 20 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): marca, tipo_bebida
## dbl (6): id, tamano_ml, azucar_g, azucar_por_100ml, calorias_kcal, con_cafeina
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
hist(bebidas$azucar_g,
main = "Gramos de azúcar por bebida",
ylab = "Frecuencia",
xlab = "Azúcar (g)",
las = 1,
ylim = c(0,15),
col = "pink")

library(ggplot2)
ggplot(bebidas, aes(x = azucar_g)) +
geom_histogram(
binwidth = 5,
fill = "#98F5FF",
color = "black"
) +
labs(
title = "Gramos de azúcar por bebida",
x = "Azúcar (g)",
y = "Frecuencia"
) +
ylim(0, 15) +
theme_minimal()

boxplot(bebidas$calorias_kcal ~ bebidas$tipo_bebida)

library(ggplot2)
plot(bebidas$azucar_g, bebidas$calorias_kcal,
main = "Relación entre azúcar y calorías",
xlab = "Azúcar (g)",
ylab = "Calorías (kcal)",
pch = 19,
col = "blue")

t <- table(bebidas$marca)
t
##
## 7UP ArizonaTe BrisaLimon BrisaManzana CocaCola Fanta
## 2 1 1 1 2 2
## Gatorade MountainDew Pepsi Powerade RedBull Sprite
## 2 2 2 1 2 2
pie(t)

pie(
table(bebidas$tipo_bebida),
labels = paste(
names(table(bebidas$tipo_bebida)),
round(table(bebidas$tipo_bebida) / sum(table(bebidas$tipo_bebida)) * 100),
"%"
),
main = "Tipo de Bebida",
col = c("purple", "blue", "pink", "turquoise")
)
