Kenneth Roy Cabrera Torres
miércoles, 04 de abril de 2018
“En resumen, la gramática nos dice que una gráfica estadística es un mapa de los datos a unos atributos estéticos (color, forma, tamaño) de unos objetos geométricos (puntos, lineas, barras). La gráfica tendrá transformaciones estadísticas que se trazan en sistemas de coordenadas específicas”
Del libro “ggplot2”
require(ggplot2)
help(mpg)
str(mpg)
head(mpg)
g1 <- ggplot(mpg, aes(displ, hwy))
g1 + geom_point()
g1 <- ggplot(mpg, aes(displ, hwy, col = drv))
g1 + geom_point()
g1 <- ggplot(mpg, aes(displ, hwy))
g1 + geom_point() + geom_smooth()
g1 <- ggplot(mpg, aes(hwy))
g1 + geom_histogram()
g1 <- ggplot(mpg, aes(hwy, fill = drv))
g1 + geom_histogram()
g1 <- ggplot(mpg, aes(displ, hwy))
g1 + geom_point() + facet_grid( . ~ drv)
g1 <- ggplot(mpg, aes(displ, hwy))
g1 + geom_point() + facet_grid( drv ~ .)
g1 <- ggplot(mpg, aes(hwy))
g1 + geom_histogram() + facet_grid( drv ~ .)
require(dataset)
require(airquality)
help(airquality)
str(airquality)
head(airquality)
require(ggplot2)
g1 <- ggplot(airquality, aes(Ozone))
g1 + geom_histogram()
require(ggplot2)
g1 <- ggplot(airquality, aes(Ozone, fill = factor(Month)))
g1 + geom_histogram()
require(ggplot2)
g1 <- ggplot(airquality, aes(Ozone))
g1 + geom_density()
require(ggplot2)
g1 <- ggplot(airquality, aes(Ozone, col = factor(Month)))
g1 + geom_density()
require(ggplot2)
g1 <- ggplot(airquality, aes(Day, Ozone))
g1 + geom_point()
require(ggplot2)
g1 <- ggplot(airquality, aes(Day, Ozone, shape=factor(Month)))
g1 + geom_point()
require(ggplot2)
g1 <- ggplot(airquality, aes(Day, Ozone, col=factor(Month)))
g1 + geom_line()
require(ggplot2)
g1 <- ggplot(subset(airquality, !is.na(Ozone)),
aes(Day, Ozone, col=factor(Month)))
g1 + geom_line()
require(ggplot2)
g1 <- ggplot(subset(airquality, !is.na(Ozone)),
aes(Day, Ozone))
g1 + geom_line() + facet_grid(. ~ Month)
require(ggplot2)
g1 <- ggplot(subset(airquality, !is.na(Ozone)),
aes(Day, Ozone))
g1 + geom_smooth() + facet_grid(. ~ Month) + geom_point()
require(ggplot2)
g1 <- ggplot(subset(airquality, !is.na(Ozone)),
aes(Day, Ozone))
g1 + geom_smooth() +
facet_grid(. ~ Month) +
geom_point() +
ggtitle("Comportamiento del ozono por mes") +
xlab("Día") +
ylab("Ozono (ppmm)")
require(ggplot2)
fecha1 <- as.Date(paste(with(airquality,seq(min(Month),max(Month))),"01"), format = "%m%d")
nombreMeses <- format(fecha1,"%B")
airquality <- transform(airquality, Mes = factor(Month, labels = nombreMeses))
g1 <- ggplot(subset(airquality, !is.na(Ozone)), aes(Day, Ozone))
g1 + geom_smooth() +
facet_grid(. ~ Mes) +
geom_point() +
ggtitle(expression(paste("Comportamiento del ozono ",O[3]," por mes"))) +
xlab("Día") + ylab(expression(paste(O[3], "(ppmm)")))
require(ggplot2)
fecha1 <- as.Date(paste(with(airquality,seq(min(Month),max(Month))),"01"), format = "%m%d")
require(Hmisc)
nombreMeses <- capitalize(format(fecha1,"%B"))
airquality <- transform(airquality, Mes = factor(Month, labels = nombreMeses))
g1 <- ggplot(subset(airquality, !is.na(Ozone)), aes(Day, Ozone))
g1 + geom_smooth() +
facet_grid(. ~ Mes) +
geom_point() +
ggtitle(expression(paste("Comportamiento del ozono ",O[3]," por mes"))) +
xlab("Día") + ylab(expression(paste(O[3], " (ppmm)")))
g1 <- ggplot(mtcars, aes(x = cyl, y = mpg, colour = factor(vs)))
g1 + geom_point() +
stat_summary(fun.y = mean, geom="line", size = 2)
g1 <- ggplot(mpg, aes(hwy))
g1 + stat_bin(aes(ymax = ..count..), geom = "area")
g1 <- ggplot(mpg, aes(hwy))
g1 + stat_bin(aes(size = ..density..), binwidth = 0.1,
geom = "point", position = "identity")