Iván Mendivelso - Credivalores
data): requiere un objeto tipo data frame.aes()): Variables a mapear según el tipo de gráfico.geom_XXX): Tipo de geometría o gráfico.x y y.geom_point()geom_line()geom_col()geom_bar()geom_boxplot()geom_histogram()geom_density()geom_smooth()geom_area()geom_jitter()Color mapeado en variables cuantitativas
Color mapeado en variables cualitativas
Ahora con el dataset mpg de {ggplot2}:
Ahora con el dataset mpg de {ggplot2}:
Comparación entre geom_bar() y geom_col()
patchwork}library(patchwork)
g1 <- ggplot(data=iris, aes(x=Sepal.Width, y=Petal.Length, col=Species)) +
geom_point()
g2 <- ggplot(mpg, aes(displ, hwy, color=drv, shape=class, size=cty, alpha=year)) +
geom_point()
g3 <- ggplot(data=iris, aes(x=Sepal.Width, y=Petal.Length, col=Sepal.Length)) +
geom_point()
(g1 + g2)/(g1 + g3)/g3Posición de variable secundaria en el relleno de las barras
b1 <- mpg |>
ggplot(aes(trans, fill=drv)) +
geom_bar(position='stack') #default
b2 <- mpg |>
ggplot(aes(trans, fill=drv)) +
geom_bar(position='dodge')
b3 <- mpg |>
ggplot(aes(trans, fill=drv)) +
geom_bar(position='fill')
b1+b2+b3Función coord_flip()
b1 <- mpg |>
ggplot(aes(trans, fill=drv)) +
geom_bar(position='stack') + #default
coord_flip()
b2 <- mpg |>
ggplot(aes(trans, fill=drv)) +
geom_bar(position='dodge') +
coord_flip()
b3 <- mpg |>
ggplot(aes(trans, fill=drv)) +
geom_bar(position='fill') +
coord_flip()
b1+b2+b3facet_wrap de {ggplot2}