Cuarteto de Anscombe
#importar los datos
anscombe <- read.csv2("~/Documents/WorkspaceR/Univalle_2023/anscombe.csv")
str(anscombe)
## 'data.frame': 44 obs. of 3 variables:
## $ Set: int 1 1 1 1 1 1 1 1 1 1 ...
## $ X : int 10 8 13 9 11 14 6 4 12 7 ...
## $ Y : num 8.04 6.95 7.58 8.81 8.33 ...
anscombe$Set <- as.factor(anscombe$Set)
str(anscombe)
## 'data.frame': 44 obs. of 3 variables:
## $ Set: Factor w/ 4 levels "1","2","3","4": 1 1 1 1 1 1 1 1 1 1 ...
## $ X : int 10 8 13 9 11 14 6 4 12 7 ...
## $ Y : num 8.04 6.95 7.58 8.81 8.33 ...
# divididir en subgrupos
uno <- subset(anscombe,anscombe$Set == "1")
promX <- mean(uno$X)
varX <- var(uno$X)
promY <- mean(uno$Y)
varY <- var(uno$Y)
corr <- cor(uno$X, uno$Y)
Hacemos la visualizacion del primer conjunto
# instalar la libreria de ggplot
# importar la libreria
library(ggplot2)
plotUno <- ggplot(uno, aes(X, Y))
plotUno <- plotUno + geom_point()
plotUno <- plotUno + geom_smooth(method=lm, se=FALSE)
plotUno <- plotUno + geom_vline(aes(xintercept = promX))
plotUno <- plotUno + geom_hline(aes(yintercept = promY))
plotUno
## `geom_smooth()` using formula = 'y ~ x'

ggplot(anscombe) +
aes(x = X, y = Y, colour = Set) +
geom_point(shape = "circle", size = 1.5) +
scale_color_hue(direction = 1) +
theme_minimal() +
facet_wrap(vars(Set))
