2025-03-27
library(tidyverse)
library(ggplot2)
library(knitr)
df <- read.csv("water_potability.csv")
df <- df %>%
drop_na()
kable(head(round(df[,5:10],2)))
| Sulfate | Conductivity | Organic_carbon | Trihalomethanes | Turbidity | Potability |
|---|---|---|---|---|---|
| 356.89 | 363.27 | 18.44 | 100.34 | 4.63 | 0 |
| 310.14 | 398.41 | 11.56 | 32.00 | 4.08 | 0 |
| 326.68 | 280.47 | 8.40 | 54.92 | 2.56 | 0 |
| 393.66 | 283.65 | 13.79 | 84.60 | 2.67 | 0 |
| 303.31 | 474.61 | 12.36 | 62.80 | 4.40 | 0 |
| 404.04 | 563.89 | 17.93 | 71.98 | 4.37 | 0 |
Esta libreria es para crear graficos interactivos en R, funciona por si solo, pero unido a ggplot2 es much más facil
install.packages("ploty")
library(plotly)
colores <- c("red","skyblue")
df$Potability <- ifelse(df$Potability == 1, "Potable", "No potable")
ggplot(data=df) +
geom_bar(aes(x= Potability, fill=Potability)) +
scale_fill_manual(values=colores,aesthetics= c("colours", "fill"))+
theme_bw()