Sei sulla pagina 1di 2

Visualización de Datos Geoms - Funciones geom se utilizan para visualizar resultados.

Geoms - Funciones geom se utilizan para visualizar resultados. Asigne variables a las propiedades estéticas del geom. Cada geom forma una capa.

usando ggplot2 Geométricas Elementales Dos Variables


a <- ggplot(economics, aes(date, unemploy))
Guía Rápida b <- ggplot(seals, aes(x = long, y = lat))
X Continua, Y Continua
e <- ggplot(mpg, aes(cty, hwy))
Distribución Bivariada Continua
h <- ggplot(diamonds, aes(carat, price))
a + geom_blank() A C e + geom_label(aes(label = cty), nudge_x = 1, h + geom_bin2d(binwidth = c(0.25, 500))
Geoms (Bueno para
- Use a geom expandir límites) nudge_y = 1, check_overlap = TRUE) x, y, alpha, color, fill, linetype, size, weight
Data Visualization to represent

b + geom_curve(aes(yend
data points, use the geom’s aesthetic properties

= lat +use1,the geom’sTwo


B to represent variables
x, y, label, alpha, angle, color, family, fontface,
Geoms
One Variable - Use a geom to represent data points, Variables
propertieshjust, lineheight, size, vjust
Data with ggplot2
Visualization
Cheat Sheet
Continuous xend=long+1,curvature=z) Continuous ) - x,X,xend, y, yend,
Continuous Y
aesthetic
e +
to represent variables
geom_jitter(height
Continuous Bivariate Distribution
= 2, width = 2)
h + geom_density2d()
x, y, alpha, colour, group, linetype, size
Conceptos Básicos One Variable Two Variables
f <- ggplot(mpg, aes(cty, hwy)) h <- ggplot(movies, aes(year, rating))
with ggplot2 a <- ggplot(mpg,
Continuous
alpha, angle, color, curvature,
aes(hwy))
f + geom_blank()
linetype, size
Continuous X, Continuous Y h + x,Continuous
y, alpha, color,
geom_bin2d(binwidth =
Bivariatefill,Distribution
c(5, shape, size
0.5))
a + geom_area(stat = "bin")
Cheat Sheet a <- ggplot(mpg, aaes(hwy))
+ size
geom_path(lineend="butt", f <- ggplot(mpg, aes(cty, hwy)) xmax,hxmin,
<- ggplot(movies, aes(year,
ymax, ymin, alpha, rating))
color, fill,
h + geom_hex()
ggplot2 se basa en la idea que cualquier gráfica se x, y, alpha, color, fill, linetype, linetype, size, weight
a + geom_area(stat = linejoin="round’
b + geom_area(aes(y = ..density..),
"bin")
stat = "bin") , linemitre=1)
f + geom_blank()
f + geom_jitter() he + geom_point()
h + geom_bin2d(binwidth = c(5, 0.5))
+ geom_density2d() x, y, alpha, colour, fill, size
puede construir usando estos tres componentes: datos,
a + geom_density(kernal = "gaussian")
x, size,
x, y, alpha, color, fill, linetype,y, size
alpha,
weight color, group, linetype, size
x, y, alpha, color, fill, shape, size y,xmax,
x, y,x,alpha,
alpha,xmin,
colour, ymax, size
color,
linetype, ymin, alpha, color, fill,
fill, shape, size, stroke
coordenadas y objetos Basics
geométricos (geoms). Este x, y,b +alpha, color, fill, linetype,
geom_area(aes(y = ..density..), stat = "bin")
linetype, size, weight
h + geom_density2d()
b + geom_density(aes(y = ..county..)) f + geom_jitter()
f + geom_point() h + geom_hex()
concepto se llama: gramática de las gráficas. a+ageom_dotplot()
+ geom_density(kernal a + geom_polygon(aes(group
= "gaussian")
color,=
fill,group))
Función Continua
Basics
x, y, alpha,
x, y, alpha, color, fill, shape,
shape,
x, alpha,
y, alpha,
size size
color, ex, y,+alpha,
geom_quantile()
x, y,colour,
alpha,fillcolour,
size linetype, size
i <- ggplot(economics, aes(date, unemploy))
x, y, color, fill fill, linetype, size, weight
F MA 4 4 b + geom_density(aes(yx, y, alpha, color, fill,fgroup,
= ..county..)) linetype, size
f + geom_point()
+ geom_quantile() x,Continuous
y,+alpha,
h geom_hex()color,
Function group, linetype, size, weight
3 3
a+ geom_dotplot()
a + geom_freqpoly() x, y, x, y,
alpha, alpha,
color, color, fill,size,
linetype, shape, size
weight g <- ggplot(economics,
x, y, alpha,aes(date,
colour, fillunemploy))
size i + geom_area()
+ 2
= 2
x, alpha,
y, alpha, color, b + geom_rect(aes(xmin = long, ymin=lat,
fill size
F MA x, y, color, linetype,
) ex, y,+alpha,
geom_rug(sides
g + geom_area()
= "bl") x, y, alpha, color, fill, linetype, size
b + geom_freqpoly(aes(y = xmax= ..density..))long + 1, ymaxf = lat
f + +geom_quantile()
1) - xmax,
+ geom_rug(sides = "bl")xmin,
41 14
Continuous
color, fill, linetype,Function
size
g <-
x,ggplot(economics,
y, alpha, color,aes(date,
linetype,unemploy))
size
ymax, ymin, alpha, color, fill, linetype, size
alpha,x,color, linetype,
color,size
30 03
0 1 2 3 4 0 1 2 3 4
a +a geom_histogram(binwidth
+ geom_freqpoly() = 5) y, alpha, linetype, size, weight
data geom
x=F
+ 2 coordinate
system
= 2
plot
x, alpha,
x, y, y, alpha, color,
color, fill, linetype, size weight
linetype, size,
f + geom_smooth(model
g + geom_line()
g + geom_area() i + geom_line()
y=A 1 1
f + geom_rug(sides == "bl")
lm) x, y, alpha,
x, y,color, linetype, sizelinetype, size
0
b +bgeom_histogram(aes(y a + geom_ribbon(aes(ymin=unemploy
+ geom_freqpoly(aes(y= =..density..))
..density..))
x, y, alpha,
alpha,color,
color,fill,linetype, -size,
900,
linetype,size weight
alpha, color, fill,
e + geom_smooth(method = lm) x, y, alpha, color, group, linetype, size
Para visualizar resultados, asigne variables a las
0

a + geom_histogram(binwidth = 5)
)
0 1 3 4 0 1 3 4

ymax=unemploy + 900) - x, ymax, ymin


2 2
data geom coordinate plot Discrete g + geom_step(direction
g + geom_line() = "hv")
propiedades
F Mvisuales,
x=F o system
estéticas, como tamaño, x, y, alpha, color, fill, linetype, size, weight
a <- ggplot(mpg, aes(fl)) f + geom_text(aes(label = cty))
f + geom_smooth(model = lm) x, y,x,alpha,
y, alpha,
x, y,color,
color,size
linetype, fill, group, linetype, size, weight
A y=A 4 4
alpha,
b + geom_histogram(aes(y color, fill, group,
= ..density..)) x, y,linetype, sizecolor, family,
label, alpha, angle, fontface,
alpha, color, linetype, size
i + geom_step(direction = "hv")
color y posición x o y. 3 3 b + geom_bar() hjust,x,lineheight,
y, alpha, color, fill, linetype, size, weight
size, vjust
+ 2
= 2 x, alpha, color, Discrete
fill, linetype, size, weight
Segmentos Lineares df <-
e + geom_text(aes(label
Cdata.frame(grp
gVisualizing
+ geom_step(direction
error
= c("A",color,
"B"), linetype,
= "hv")= cty), nudge_x = 1,
fit = 4:5, se = 1:2) x, y, alpha, color, group, linetype, size
a <- ggplot(mpg, aes(fl)) f + geom_text(aes(label = cty)) x, y, alpha, size
A nudge_y = 1, check_overlap = TRUE)
1 1
F MA 4
0
4
0
propiedades
b + geom_bar() básicas: x, y, alpha, x,color,
y, label,
Discrete linetype,
alpha, Ysize
angle, color,
X, Continuous e B
<- ggplot(df,
family, fontface, aes(grp, fit, ymin = fit-se, ymax = fit+se))
x, y, label, alpha, angle, color, family, fontface,
1 30 1

data geom
3 0
coordinate
2 3 4

plot
2 3 4
Graphical Primitives hjust, lineheight,
g <- ggplot(mpg, size, vjust
aes(class, hwy))
+ system = x, alpha, color, fill, linetype, size, weight e + geom_crossbar(fatten
dfx,<-y,hjust,
Visualizing
lineheight,
= 2)error Visualizando el Error
color, size, fitvjust
2 2
x=F
y=A b + geom_abline(aes(intercept=0,
g + geom_bar(stat = slope=1) "identity") ) data.frame(grp
ymax, ymin, = c("A",
alpha, "B"),
fill, = 4:5, se = 1:2)
linetype,
df <- data.frame(grp = c("A", "B"), fit = 4:5, se = 1:2)
1 1
color = F
c <- ggplot(map, aes(long, lat)) e <-size
ggplot(df, aes(grp, fit, ymin = fit-se, ymax = fit+se))
size = A 0 0
b + geom_hline( aes(yintercept
x, y, alpha,
Discretecolor,=fill,
X,lat) ) size, weight
linetype,
Continuous Y
e + geom_errorbar()
j <- ggplot(df, aes(grp, fit, ymin = fit-se, ymax = fit+se))
0 1 3 4 0 1 3 4
Graphical Primitives
2
c + geom_polygon(aes(group
2
data geom coordinate plot = group)) g <- ggplot(mpg, aes(class, hwy))
x=F system b +size
x, y, alpha, color, fill, linetype, geom_vline(aes(xintercept
g + geom_boxplot() = long)) X Discreta, Y Continua
e +ymin,
x, ymax, geom_crossbar(fatten = 2)
alpha, color, linetype, size,
y=A
color = F
b + geom_segment(
g +middle,
lower,
aes(yend=lat+1,
geom_bar(stat
upper, x, ymax,
xend=long+1))
= "identity")
ymin, alpha, f <- ggplot(mpg, aes(class, hwy))
x, y,geom_errorbarh())
width (also ymax, ymin, alpha, color, fill, linetype,
size = A c <- ggplot(map, aes(long, lat)) color,x,fill, linetype,
y, alpha, color,shape,fill,size, weightsize, weight
linetype, size
e + geom_linerange() j + geom_crossbar(fatten = 2)
Para construir una gráfica complete este patrón g <- ggplot(economics,
b + geom_spoke(
aes(date, unemploy))aes(angle = 1:1155, radius = 1))
c + geom_polygon(aes(group = group)) g + geom_dotplot(binaxis = "y", e +ymax,
x, ymin, geom_errorbar()
alpha, color, linetype, size
x, y, ymax, ymin, alpha, color, fill, group,
g + geom_boxplot()
stackdir = "center")
x, y, alpha, color, fill, linetype, size f + geom_col()
x, ymax, ymin, alpha, color, linetype, size,
g + geom_path(lineend="butt", x, y, alpha,
lower,color, fill upper, x, ymax, ymin, alpha, e + geom_pointrange()
width (also geom_errorbarh()) linetype, size
ggplot(data = <DATA > ) +
<DATOS> Requeridolinejoin="round’, linemitre=1) middle,
x, y,x,ymin,
ey,+alpha, color,
ymax, alpha, fill,linetype,
color, fill, group, linetype, size
x, y, alpha, color, linetype, size Una Variable
g + geom_violin(scale
color, fill, linetype,= shape,
x, y,galpha,
+ geom_dotplot(binaxis
"area")size, weight
color, fill, linetype, size, =
weight
"y",
shape, size
geom_linerange()
x, ymin, ymax, alpha, color, linetype, size
j + geom_errorbar()
<GEOM_FUNCTION>
<FUNCION_GEOM> (
F MA 4 4
g <-g ggplot(economics, aes(date, unemploy))
+ geom_ribbon(aes(ymin=unemploy - 900,
stackdir = "center") Maps f + geom_boxplot() x, ymax, ymin, alpha, color, group, linetype,
mapping =aes( 3 <MAPPINGS> <ESTETICAS> ), 3 ymax=unemploy
g + + 900))
geom_path(lineend="butt",
Continua
x, y, alpha, color, fill e + geom_pointrange()
data <- data.frame(murder = USArrests$Murder, size, width (also geom_errorbarh())
x, ymax, ymin, alpha, color, fill, linetype, size
stat = <STAT> <STAT> 1 +2

,
2
= linejoin="round’ c <- ggplot(mpg,
, linemitre=1) aes(hwy)); c2 <-
Discrete
g + ggplot(mpg)
X, Discrete Y= "area")
geom_violin(scale
state
map <-
=
x, y, x,lower,
y, ymin, ymax,
map_data("state") middle,
tolower(rownames(USArrests))) alpha, upper, ymax, ymin, alpha,
color, fill, linetype,
j + geom_linerange()
1 No x, y, alpha, color, linetype, size h <- ggplot(diamonds, aes(cut, color))
color,
x, y, alpha, color, fill, linetype, size, weight e <- ggplot(data,
shape,
fill,size= murder))
aes(fill group, linetype, shape, size, weight
position
F M A = <POSITION> <POSICION>
0 0
Requerido, d<-gggplot(seals,
+ geom_ribbon( aes(xaes(ymin=unemploy
= long, y = lat)) - 900, h + geom_jitter() e + geom_map(aes(map_id = state), map = map) + x, ymin, ymax, alpha, color, group, linetype, size
c + geom_area(stat = "bin") f + geom_dotplot(binaxis = "y",
Maps
4 0 1 2 3 4 40 1 2 3 4

data geom 3 coordinate plot ymax=unemploy + 900)) expand_limits( x = map$long, y ==map$lat


data <- data.frame(murder )
USArrests$Murder,
) + x=F system
3
se proveen d + geom_segment(aes(
x, ymax, ymin, alpha, color, fill, linetype, size
x, y, alpha, color, fill, shape, size
state = tolower(rownames(USArrests)))
<FUNCION_COORDINADAS>
y=A
+ 2 2
= valores xend = long + delta_long, x, y, alpha, color, fill, linetype, size
Discrete X, Discrete Y map_id, alpha, color, fill, linetype, size
map <- map_data("state") stackdir = "center") j + geom_pointrange()
<COORDINATE_FUNCTION> + 1 yend = lat + delta_lat)) h <- ggplot(diamonds, aes(cut, color))
Three Variables ex, y, alpha, aes(fill
<- ggplot(data, color,= fill, group
murder))
1

iniciales x, y, ymin, ymax, alpha, color, fill, group,


<FUNCION_FACETA> 0 +1 2 3 4
<FACET_FUNCTION> x, xend, y, yend, alpha, color, linetype, size
c + geom_density(kernel = "gaussian") e + geom_map(aes(map_id = state), map = map) +
0 0
d<- ggplot(seals, aes(x = long, y = lat)) h + geom_jitter()
f + geom_violin(scale = "area") linetype, shape, size
0 1 3 4
i + geom_raster(aes(fill = z), hjust=0.5,
2
data geom coordinate plot seals$z <- with(seals, sqrt(delta_long^2 + delta_lat^2))
d + geom_rect(aes(xmin = long, ymin = lat, x, aes(long,
y, alpha, color, expand_limits( x = map$long, y = map$lat)
lat)) fill, shape, size
long + delta_long, x, y, alpha, color, fill, group, linetype, size, weight
<SCALE_FUNCTION>
<FUNCION_ESCALA> x=F +
system d + geom_segment(aes( i <- ggplot(seals, vjust=0.5, interpolate=FALSE)
map_id, alpha, color, fill, linetype, size
y=A xmax=
xend= lat
ymax = long + delta_long,
+ delta_lat))
x,alpha,
x, y, y, alpha,
fill color, fill, group, linetype, size,
<THEME_FUNCTION>
<FUNCION_TEMA> yend = lat + delta_lat))
xmax, xmin, ymax, ymin, alpha, color, fill,
i + geom_contour(aes(z = z))
c + geom_dotplot() Three Variables weight
i + geom_tile(aes(fill = z))
Mapas
x, xend,size
linetype, y, yend, alpha, color, linetype, size x, y, z, alpha, colour, linetype, size, weight x, y, alpha, color, fill, linetype, size
d + geom_rect(aes(xminx,= y, alpha,
ymin =color,
seals$z <- with(seals, sqrt(delta_long^2 + delta_lat^2))
fill i + geom_raster(aes(fill = z), hjust=0.5, data <- data.frame(murder = USArrests$Murder,
ggplot(data = mpg, aes(x = cty, y = hwy)) long, lat, i <- ggplot(seals, aes(long, lat)) vjust=0.5, interpolate=FALSE) state = tolower(rownames(USArrests)))
RStudio® is a trademark of RStudio, Inc. • CC BY RStudio • info@rstudio.com • 844-448-1212xmax= long + delta_long,
• rstudio.com X Discreta, Y Discreta
Learn more at docs.ggplot2.org • ggplot2 0.9.3.1 • Updated: 3/15
Este comando comienza una gráfica, complétela ymax = lat + delta_lat)) c + geom_freqpoly()
x, y, alpha, fill map <- map_data("state")
xmax, xmin, ymax, ymin, alpha, color, fill,
i + geom_contour(aes(z = z)) g <- ggplot(diamonds,
i + geom_tile(aes(fill = z)) aes(cut, color)) k <- ggplot(data, aes(fill = murder))
mediante agregando capas, un geom por capa. linetype, size x, y, alpha, color, group, x,linetype, size linetype, size, weight
y, z, alpha, colour, x, y, alpha, color, fill, linetype, size
g + geom_count() k + geom_map(aes(map_id = state), map = map) +
estéticas datos geom
RStudio® is a trademark of RStudio, Inc. • CC BY RStudio • info@rstudio.com • 844-448-1212 • rstudio.com c + geom_histogram(binwidth = 5) Learn more at docs.ggplot2.org • ggplot2 0.9.3.1 • Updated: 3/15
x, y, alpha, color, fill, shape, size, stroke expand_limits(x = map$long, y = map$lat)
qplot(x = cty, y = hwy, data = mpg, geom = "point") x, y, alpha, color, fill, linetype, size, weight map_id, alpha, color, fill, linetype, size
Este comando es una gráfica completa, tiene datos, las
estéticas están asignadas y por lo menos un geom. c2 + geom_qq(aes(sample = hwy)) Tres Variables Argumentos
x, y, alpha, color, fill, linetype, size, weight seals$z <- with(seals, sqrt(delta_long^2 l + geom_raster(aes(fill = z), Traducción de argumentos comunes
last_plot()
+ delta_lat^2)) hjust=0.5, vjust=0.5, label = etiqueta, angle=ángulo
Devuelve la última gráfica Discreta interpolate=FALSE)
l <- ggplot(seals, aes(long, lat)) size=tamaño, weight=peso
d <- ggplot(mpg, aes(fl)) x, y, alpha, fill alpha=transparencia
ggsave("plot.png", width = 5, height = 5) l + geom_contour(aes(z = z)) fontface=tipo de letra
d + geom_bar() l + geom_tile(aes(fill = z))
La última gráfica es grabada como una imagen de 5 por x, y, z, alpha, colour, group, hjust=ajuste horizontal
x, y, alpha, color, fill, linetype, size, lineheight=grosor de línea
5 pulgs., usa el mismo tipo de archivo que la extensión x, alpha, color, fill, linetype, size, weight linetype, size, weight width

RStudio® es una marca registrada de RStudio, Inc. • CC BY RStudio • info@rstudio.com • 844-448-1212 • rstudio.com Para aprender más vaya a docs.ggplot2.org y www.ggplot2-exts.org • ggplot2 2.1.0 • Actualizado: 12/16
Stats - Otra manera de construir una capa Escalas Sistema de Coordenadas Facetas
Las escalas asignan los valores que hay en los datos a r <- d + geom_bar() Las Facetas dividen una gráfica en multiple sub-
Stat crea nuevas variables para la gráfica, como count
fl cty cyl 4 4
los valores visuales de una estética. r + coord_cartesian(xlim = c(0, 5)) gráficas basada en una o varias variables discretas
x ..count..
3 3 xlim, ylim t <- ggplot(mpg, aes(cty, hwy)) + geom_point()
+ 2
= 2 (n <- d + geom_bar(aes(fill = fl))) Usa coordenadas cartesianas
t + facet_grid(. ~ fl)
1 1

0
0 1 2 3 4
0
0 1 2 3 4
escala
estética escala del argumentos r + coord_fixed(ratio = 1/2) usa fl para dividir en columnas
data stat geom coordinate plot afectada paquete
x=x system de la escala ratio, xlim, ylim
y = ..count..
t + facet_grid(year ~ .)
n + scale_fill_manual( Se fija la relación de aspecto usa year para dividir en lineas
Cambie el Stat que la función Geom usa para visualizarla, values = c("skyblue", "royalblue", "blue", "navy"), r + coord_flip() t + facet_grid(year ~ fl)
así: geom_bar(stat=“count”). También puede usar la limits = c("d", "e", "p", "r"), breaks =c("d", "e", "p", "r"),
función Stat, así: stat_count(geom=“bar") que igual name = "fuel", labels = c("D", "E", "P", "R")) xlim, ylim usa los dos para dividir
como una función Geom, esta función también crea una Las coordenadas son volteadas t + facet_wrap(~ fl)
valores etiqueta de cada intervalo de cada
capa. permitidos
título del eje
valor visible r + coord_polar(theta = "x", direction=1 ) divide en una manera rectangular
valor visible
theta, start, direction Use scales para que dejar que el límite cambie por cada
función geom función stat geométricas
Coordenadas polares faceta
Escalas para todo uso t + facet_grid(drv ~ fl, scales = "free")
i + stat_density2d(aes(fill = ..level..), Uselas con la mayoría de las estéticas r + coord_trans(ytrans = "sqrt")
geom = "polygon") variable que stat créa Cada faceta tiene limites x e y indpendientes
scale_*_continuous() - asigna valores continuos a xtrans, ytrans, limx, limy
• "free_x" - ajusta el límite del eje x
Distribución visuales xtrans e ytrans se asignan a funciones
c + stat_bin(binwidth = 1, origin = 10) Unidimensional ventanas para transformar las • "free_y" - ajusta el límite del eje y
scale_*_discrete() - asigna valores discretos a visuales
x, y | ..count.., ..ncount.., ..density.., ..ndensity.. scale_*_identity() - crea una estética visual por cada valor coordenadas cartesianas Use labeller para cambiar las etiquetas de las facetas
c + stat_count(width = 1) x, y, | ..count.., ..prop.. scale_*_manual(values = c()) - asigna valores específicos t + facet_grid(. ~ fl, labeller = label_both)
c + stat_density(adjust = 1, kernel = "gaussian") a valores visuales escogidos manualmente. 60

π + coord_quickmap() fl: c fl: d fl: e fl: p fl: r


x, y, | ..count.., ..density.., ..scaled.. scale_*_date(date_labels = "%m/%d"),
π + coord_map(projection = "ortho",

lat
date_breaks = "2 weeks") - Usa los valores como fechas t + facet_grid(fl ~ ., labeller = label_bquote(alpha ^ .(fl)))
scale_*_datetime() - Usa los valores como fecha-horas orientation=c(41, -74, 0)) ↵c ↵d ↵e ↵p ↵r
Distribución
e + stat_bin_2d(bins = 30, drop = T) Bidimensional Igual que scale_*_date pero usando strptime projection, orientation, xlim, ylim long
t + facet_grid(. ~ fl, labeller = label_parsed)
x, y, fill | ..count.., ..density.. Usa el paquete mapproj para proyectar mapas c d e p r
e + stat_bin_hex(bins=30) x, y, fill | ..count.., ..density..
Escalas de localización para X e Y
e + stat_density_2d(contour = TRUE, n = 100) Use con las estéticas x e y (aquí se muestra x) Ajustes a las posiciones Etiquetas
x, y, color, size | ..level..
scale_x_log10() - Usa escala logarítmica base 10 Determina que hacer con Geoms que ocuparían la t + labs( x = “Etiqueta X", y = “Etiqueta Y",
e + stat_ellipse(level = 0.95, segments = 51, type = "t") misma posición en la gráfica. Use
scale_x_reverse() - Posiciona x al revés title =“Título de la gráfica",
funciones
scale_x_sqrt() - Usa escala raíz cuadrada s <- ggplot(mpg, aes(fl, fill = drv)) subtitle = "Subtítulo de la gráfica", escalas para
l + stat_contour(aes(z = z)) x, y, z, order | ..level..
s + geom_bar(position = "dodge") caption = "Nota de la gráfica", controlar las
l + stat_summary_hex(aes(z = z), bins = 30, fun = max) Escalas para Color y Relleno (Discretas) etiquetas de
Pone los elementos a lado de cada uno <aes>
<AES> = “Texto in la <AES> “) las leyendas
x, y, z, fill | ..value.. n <- d + geom_bar(aes(fill = fl))
l + stat_summary_2d(aes(z = z), bins = 30, fun = mean) s + geom_bar(position = "fill") t + annotate(geom = "text", x = 8, y = 9, label = "A")
n + scale_fill_brewer(palette = "Blues")
x, y, z, fill | ..value.. 3 Variables Ver opciones de colores: RColorBrewer::display.brewer.all() Pone los elementos encima the cada uno Anotaciones
y usa toda la altura de la gráfica geom a usar valores manuales del geom
n + scale_fill_grey(start = 0.2, end = 0.8, na.value
f + stat_boxplot(coef = 1.5) Comparativas = "red") e + geom_point(position = "jitter")
x, y | ..lower.., ..middle.., ..upper.., ..width.. , ..ymin.., ..ymax.. Agrega ruido a los elementos Leyendas
f + stat_ydensity(kernel = "gaussian", scale = "area") Escalas para Color y Relleno (Continuas) A
e + geom_label(position = "nudge") n + theme(legend.position = "bottom")
x, y | ..density.., ..scaled.., ..count.., ..n.., ..violinwidth.., ..width.. o <- c + geom_dotplot(aes(fill = ..x..)) B
Empuja las letras para ver los puntos Pone la leyenda debajo (bottom), arriba(top),
o + scale_fill_distiller(palette = "Blues") s + geom_bar(position = "stack") izquierda (left), o derecha (right)
e + stat_ecdf(n = 40) x, y | ..x.., ..y.. Funciones Pone los elementos encima the cada uno n + guides(fill = "none")
o + scale_fill_gradient(low="red", high="yellow")
e + stat_quantile(quantiles = c(0.1, 0.9), Tipo de leyenda por cada estética : colorbar, legend,
Cada ajuste se puede usar como función para fijar el or none (no legend)
formula = y ~ log(x), method = "rq") x, y | ..quantile.. o + scale_fill_gradient2(low="red", high="blue",
mid = "white", midpoint = 25) ancho and alto n + scale_fill_discrete(name = "Title",
e + stat_smooth(method = "lm", formula = y ~ x, labels = c("A", "B", "C", "D", "E"))
se=T, level=0.95) x, y | ..se.., ..x.., ..y.., ..ymin.., ..ymax.. o + scale_fill_gradientn(colours=topo.colors(6)) s + geom_bar(position = position_dodge(width = 1))
También: rainbow(), heat.colors(), terrain.colors(), Fija el título y etiquetas de la leyenda
cm.colors(), RColorBrewer::brewer.pal()
ggplot() + stat_function(aes(x = -3:3), n = 99, Tema Agrandar una sección
fun = dnorm, args = list(sd=0.5)) x | ..x.., ..y.. Escalas que usan tamaño y figuras Sin cortar (preferido)
r + theme_bw() r + theme_classic()
150

p <- e +Manual shape values


150

e + stat_identity(na.rm = TRUE) geom_point(aes(shape = fl, size = cyl)) 100

t + coord_cartesian(
count

100
count

Fondo blanco con r + theme_light()


50 50

ggplot() + stat_qq(aes(sample=1:100), dist = qt, p + scale_shape() + scale_size() xlim = c(0, 100), ylim = c(10, 20))
0 0

cuadrícula
c d e p r c d e p r
fl fl

r + theme_linedraw()
dparam=list(df=5)) sample, x, y | ..sample.., ..theoretical.. p + scale_shape_manual(values = c(3:7)) 150

r + theme_gray()
150

100

r + theme_minimal()
count

Cortando (quita los puntos escondidos)


100
count

e + stat_sum() x, y, size | ..n.., ..prop.. Fondo gris


50
0:1

50

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Temas minimalisticos
0

(tema inicial) t + xlim(0, 100) + ylim(10, 20)


c d e p r 0

fl

e + stat_summary(fun.data = "mean_cl_boot")
c d e p r
fl

150

r + theme_dark() r + theme_void() t + scale_x_continuous(limits = c(0, 100)) +


h + stat_summary_bin(fun.y = "mean", geom = "bar") p + scale_radius(range = c(1,6))
100
count

Usa el radio 50

Obscuro Tema vacío scale_y_continuous(limits = c(0, 100))


e + stat_unique() Todo Uso p + scale_size_area(max_size = 6) o el area
0

c d e p r
fl

RStudio® es una marca registrada de RStudio, Inc. • CC BY RStudio • info@rstudio.com • 844-448-1212 • rstudio.com Para aprender más vaya a docs.ggplot2.org y www.ggplot2-exts.org • ggplot2 2.1.0 • Actualizado: 12/16
c(-1, 26)

Potrebbero piacerti anche