# Cargar el dataset trees y convertirlo en un data frame
data(trees)
df <- data.frame(trees)
# Verificar las columnas del data frame
str(df)
## 'data.frame': 31 obs. of 3 variables:
## $ Girth : num 8.3 8.6 8.8 10.5 10.7 10.8 11 11 11.1 11.2 ...
## $ Height: num 70 65 63 72 81 83 66 75 80 75 ...
## $ Volume: num 10.3 10.3 10.2 16.4 18.8 19.7 15.6 18.2 22.6 19.9 ...
Arboles <- subset(df, Height >= 70 & Height <= 80 & Girth < 13)
# Crear un gráfico de puntos (cuadrados) de diámetro vs altura
plot(df$Girth, df$Height,
pch = 15,
col = ifelse(df$Height >= 70 & df$Height <= 80 & df$Girth < 13, "green", "black"), xlab = "Diámetro (pulgadas)", ylab = "Altura (pies)",main = "Altura y Ancho de Árboles Cherry Negros")
# Agregar una leyenda
legend("topright",
legend = c("Cumple filtro", "No cumple filtro"),
col = c("green", "black"),
pch = 15,
title = "Diámetro vs Altura")
