Visualização de dados com
ggplot2
Prof. Walmes Zeviani
walmes@[Link]
Laboratório de Estatística e Geoinformação
Departamento de Estatística
Universidade Federal do Paraná
Walmes Zeviani · UFPR Visualização de dados com ggplot2 1
Recursos gráficos do R
Walmes Zeviani · UFPR Visualização de dados com ggplot2 2
Visão geral
O landscape de recursos para visualização de dados no R pode ser
representado por uma divisão em 4 territórios.
1. O pacote graphics e derivados.
2. O pacote lattice e derivados.
3. O pacote ggplot2 e derivados.
4. Pacotes para gráficos interativos.
Walmes Zeviani · UFPR Visualização de dados com ggplot2 3
O pacote graphics
I Contém os recursos mais primitivos: com funções de alto e baixo
nível.
I Pouco suporte para mapeamento em variáveis visuais retinais.
I Vários pacotes que complementam suas funcionalidades: plotrix
e gplots.
I Usado em métodos gráficos de saídas de análises: dendrogramas,
biplots, etc.
Walmes Zeviani · UFPR Visualização de dados com ggplot2 4
O pacote lattice
I Desenvolvido por Deepayan Sarkar.
I Plotagem multi-painel e mapeamento em variáveis visuais retinais.
I Já vem com a instalação básica do R.
I Também é utilizado na implementação de métodos gráficos.
Walmes Zeviani · UFPR Visualização de dados com ggplot2 5
O pacote ggplot2
I Desenvolvido por Hadley Wickham.
I Baseado na Grammar of Graphics.
I Plotagem multi-painel e mapeamento em variáveis visuais retinais.
I A importância da ggplot2 está no modelo mental mais claro.
Walmes Zeviani · UFPR Visualização de dados com ggplot2 6
Pacotes para recursos interativos
A visualização interativa é voltada para exibicação na WEB. Alguns dos
pacotes para isso são estes:
I plotly.
I highcharter.
I googleVis.
I rCharts.
I leaflet.
I iplots.
I rgl.
I animation.
Walmes Zeviani · UFPR Visualização de dados com ggplot2 7
Mais informação
Para mais detalhes sobre os recursos gráficos, siga esse link: https://
[Link]/~jenny/STAT545A/block90_baseLatticeGgplot2.html.
Para uma descrição completada comparação entre lattice e ggplot2,
siga esse link: [Link]
ggplot2-version-of-figures-in-lattice-multivariate-data-visualization-with-r-final-p
Confira no R Graph Gallery a variedade de gráficos confeccionados com
o R.
Walmes Zeviani · UFPR Visualização de dados com ggplot2 8
Galerias e tutoriais
Walmes Zeviani · UFPR Visualização de dados com ggplot2 9
The R Graph Gallery
Figura 1. Gráficos da galeria de gráficos do R. Fonte: Mara Averick.
Walmes Zeviani · UFPR Visualização de dados com ggplot2 10
Galerias
I [Link]
I [Link]
[Link].
I [Link]
I [Link]
[Link].
Walmes Zeviani · UFPR Visualização de dados com ggplot2 11
Extensões do ggplot2
Figura 2. Gráficos da galeria de extensões do ggplot2. Fonte: GGally.
I [Link]
I [Link]
Walmes Zeviani · UFPR Visualização de dados com ggplot2 12
Mapas
I [Link]
[Link].
I [Link]
2017-05-04-mapas-tematicos-3-minutos/.
I [Link]
[Link].
Walmes Zeviani · UFPR Visualização de dados com ggplot2 13
Tutoriais em português
I [Link]
I [Link]
I [Link]
beautiful-thematic-maps-with-ggplot2-only/.
I [Link]
I [Link]
[Link].
I [Link]
inteligencia-geografica-gerando-mapas-em-r/.
I [Link]
r-mapa-de-cidades-brasileiras.
Walmes Zeviani · UFPR Visualização de dados com ggplot2 14
Um overview do ggplot2
Walmes Zeviani · UFPR Visualização de dados com ggplot2 15
A ficha técnica
Figura 3. Ficha técnica do ggplot2.
Walmes Zeviani · UFPR Visualização de dados com ggplot2 16
Gramática dos gráficos
Figura 4. Leland Wilkinson (esq.) autor de “The grammar of graphics” (meio) e as
camadas da gramática de gráficos que são usadas no ggplot2.
Walmes Zeviani · UFPR Visualização de dados com ggplot2 17
Gramática dos gráficos
Figura 5. As camadas na gramática dos gráficos.
Walmes Zeviani · UFPR Visualização de dados com ggplot2 18
Camada 1: dados
Figura 6. A camada dos dados.
Walmes Zeviani · UFPR Visualização de dados com ggplot2 19
Camada 1: dados
Deve se estar atento ao tipo de valor/objeto.
I Quantitativa: variável numérica discreta ou contínua.
I Qualitativa: variável nominal ou ordinal.
I Cronológica: variável de data ou data-tempo.
I Geográfica: objeto como polígonos, por exemplo.
Walmes Zeviani · UFPR Visualização de dados com ggplot2 20
Camada 2: mapeamento em variáveis visuais
Figura 7. A camada de mapeamento dos valores em variáveis visuais.
Walmes Zeviani · UFPR Visualização de dados com ggplot2 21
Camada 2: mapeamento em variáveis visuais
Figura 8. Variáveis visuais disponíveis no ggplot2.
Walmes Zeviani · UFPR Visualização de dados com ggplot2 22
Camada 2: mapeamento em variáveis visuais
Funções para controle de escala:
scale_alpha_:
continuous date datetime discrete identity manual ordinal
scale_colour_:
brewer continuous date datetime discrete distiller gradient
gradient2 gradientn grey hue identity manual ordinal
scale_continuous_:
identity
scale_discrete_:
identity manual
scale_fill_:
brewer continuous date datetime discrete distiller gradient
gradient2 gradientn grey hue identity manual ordinal
scale_linetype_:
continuous discrete identity manual
scale_shape_:
continuous discrete identity manual ordinal
scale_size_:
area continuous date datetime discrete identity manual ordinal
scale_x_:
continuous date datetime discrete log10 reverse sqrt time
scale_y_:
continuous date datetime discrete log10 reverse sqrt time
Walmes Zeviani · UFPR Visualização de dados com ggplot2 23
Camada 3: geometrias
Figura 9. A camada de elementos geométricos.
Walmes Zeviani · UFPR Visualização de dados com ggplot2 24
Camada 3: geometrias
Funções disponíveis para a camada de geometria:
geom_abline geom_freqpoly geom_rect
geom_area geom_hex geom_ribbon
geom_bar geom_histogram geom_rug
geom_bin2d geom_hline geom_segment
geom_blank geom_jitter geom_sf
geom_boxplot geom_label geom_sf_label
geom_col geom_line geom_sf_text
geom_contour geom_linerange geom_smooth
geom_count geom_map geom_spoke
geom_crossbar geom_path geom_step
geom_curve geom_point geom_text
geom_density geom_pointrange geom_tile
geom_density2d geom_polygon geom_violin
geom_density_2d geom_qq geom_vline
geom_dotplot geom_qq_line update_geom_defaults
geom_errorbar geom_quantile
geom_errorbarh geom_raster
Walmes Zeviani · UFPR Visualização de dados com ggplot2 25
Camada 4: divisão em facetas
Figura 10. A camada da divisão em facetas.
Walmes Zeviani · UFPR Visualização de dados com ggplot2 26
Camada 4: divisão em facetas
Funções disponíveis para divisão em facetas:
facet_grid
facet_null
facet_wrap
Walmes Zeviani · UFPR Visualização de dados com ggplot2 27
Camada 5: estatística
Figura 11. A camada de elementos de estatística
Walmes Zeviani · UFPR Visualização de dados com ggplot2 28
Camada 5: estatística
Funções disponíveis para a camada estatística:
stat_bin stat_ecdf stat_sum
stat_bin2d stat_ellipse stat_summary
stat_bin_2d stat_function stat_summary2d
stat_binhex stat_identity stat_summary_2d
stat_bin_hex stat_qq stat_summary_bin
stat_boxplot stat_qq_line stat_summary_hex
stat_contour stat_quantile stat_unique
stat_count stat_sf stat_ydensity
stat_density stat_sf_coordinates update_stat_defaults
stat_density2d stat_smooth
stat_density_2d stat_spoke
Walmes Zeviani · UFPR Visualização de dados com ggplot2 29
Camada 6: coordenadas
Figura 12. A camada do sistema de coordenadas.
Walmes Zeviani · UFPR Visualização de dados com ggplot2 30
Camada 6: coordenadas
Funções disponíveis para a camada de coordenadas:
coord_cartesian
coord_equal
coord_fixed
coord_flip
coord_map
coord_munch
coord_polar
coord_quickmap
coord_sf
coord_trans
Walmes Zeviani · UFPR Visualização de dados com ggplot2 31
Camada 7: tema
Figura 13. A camada de tema.
Walmes Zeviani · UFPR Visualização de dados com ggplot2 32
Camada 7: tema
Funções disponíveis para a camada de tema:
theme_bw
theme_classic
theme_dark
theme_get
theme_gray
theme_grey
theme_light
theme_linedraw
theme_minimal
theme_replace
theme_set
theme_test
theme_update
theme_void
TODO WALMES FIXME e quais as funções que sobram? 1
ls_ggplot %>% 2
str_subset("[[:upper:]]", negate = TRUE) 3
Walmes Zeviani · UFPR Visualização de dados com ggplot2 33
Data Visualization with ggplot2 : : CHEAT SHEET
Basics Geoms Use a geom function to represent data points, use the geom’s aesthetic properties to represent variables.
Each function returns a layer.
GRAPHICAL PRIMITIVES TWO VARIABLES
ggplot2 is based on the grammar of graphics, the idea
that you can build every graph from the same a <- ggplot(economics, aes(date, unemploy)) continuous x , continuous y continuous bivariate distribution
components: a data set, a coordinate system, b <- ggplot(seals, aes(x = long, y = lat)) h <- ggplot(diamonds, aes(carat, price))
e <- ggplot(mpg, aes(cty, hwy))
and geoms—visual marks that represent data points. a + geom_blank()
e + geom_label(aes(label = cty), nudge_x = 1, h + geom_bin2d(binwidth = c(0.25, 500))
(Useful for expanding limits) nudge_y = 1, check_overlap = TRUE) x, y, label, x, y, alpha, color, fill, linetype, size, weight
F M A alpha, angle, color, family, fontface, hjust,
b + geom_curve(aes(yend = lat + 1,
lineheight, size, vjust
+ = xend=long+1,curvature=z)) - x, xend, y, yend,
alpha, angle, color, curvature, linetype, size e + geom_jitter(height = 2, width = 2)
h + geom_density2d()
x, y, alpha, colour, group, linetype, size
x, y, alpha, color, fill, shape, size
data geom coordinate plot a + geom_path(lineend="butt", linejoin="round", h + geom_hex()
x=F·y=A system linemitre=1)
x, y, alpha, colour, fill, size
e + geom_point(), x, y, alpha, color, fill, shape,
x, y, alpha, color, group, linetype, size size, stroke
To display values, map variables in the data to visual a + geom_polygon(aes(group = group))
e + geom_quantile(), x, y, alpha, color, group,
properties of the geom (aesthetics) like size, color, and x x, y, alpha, color, fill, group, linetype, size linetype, size, weight
continuous function
and y locations. i <- ggplot(economics, aes(date, unemploy))
b + geom_rect(aes(xmin = long, ymin=lat, xmax=
F M A long + 1, ymax = lat + 1)) - xmax, xmin, ymax, e + geom_rug(sides = "bl"), x, y, alpha, color, i + geom_area()
ymin, alpha, color, fill, linetype, size x, y, alpha, color, fill, linetype, size
+ =
linetype, size
a + geom_ribbon(aes(ymin=unemploy - 900, e + geom_smooth(method = lm), x, y, alpha, i + geom_line()
ymax=unemploy + 900)) - x, ymax, ymin, color, fill, group, linetype, size, weight x, y, alpha, color, group, linetype, size
data geom coordinate plot alpha, color, fill, group, linetype, size
x=F·y=A system e + geom_text(aes(label = cty), nudge_x = 1,
color = F i + geom_step(direction = "hv")
size = A nudge_y = 1, check_overlap = TRUE), x, y, label, x, y, alpha, color, group, linetype, size
alpha, angle, color, family, fontface, hjust,
LINE SEGMENTS lineheight, size, vjust
common aesthetics: x, y, alpha, color, linetype, size
b + geom_abline(aes(intercept=0, slope=1)) visualizing error
Complete the template below to build a graph. b + geom_hline(aes(yintercept = lat)) df <- [Link](grp = c("A", "B"), fit = 4:5, se = 1:2)
required b + geom_vline(aes(xintercept = long)) discrete x , continuous y j <- ggplot(df, aes(grp, fit, ymin = fit-se, ymax = fit+se))
ggplot (data = <DATA> ) + f <- ggplot(mpg, aes(class, hwy))
<GEOM_FUNCTION> (mapping = aes( <MAPPINGS> ), b + geom_segment(aes(yend=lat+1, xend=long+1)) j + geom_crossbar(fatten = 2)
f + geom_col(), x, y, alpha, color, fill, group, x, y, ymax, ymin, alpha, color, fill, group, linetype,
b + geom_spoke(aes(angle = 1:1155, radius = 1)) size
stat = <STAT> , position = <POSITION> ) + Not
linetype, size
<COORDINATE_FUNCTION> + required,
sensible j + geom_errorbar(), x, ymax, ymin, alpha, color,
f + geom_boxplot(), x, y, lower, middle, upper, group, linetype, size, width (also
<FACET_FUNCTION> + defaults
supplied ONE VARIABLE continuous ymax, ymin, alpha, color, fill, group, linetype, geom_errorbarh())
<SCALE_FUNCTION> + c <- ggplot(mpg, aes(hwy)); c2 <- ggplot(mpg) shape, size, weight
j + geom_linerange()
<THEME_FUNCTION> f + geom_dotplot(binaxis = "y", stackdir = x, ymin, ymax, alpha, color, group, linetype, size
c + geom_area(stat = "bin")
"center"), x, y, alpha, color, fill, group
x, y, alpha, color, fill, linetype, size j + geom_pointrange()
ggplot(data = mpg, aes(x = cty, y = hwy)) Begins a plot f + geom_violin(scale = "area"), x, y, alpha, color, x, y, ymin, ymax, alpha, color, fill, group, linetype,
that you finish by adding layers to. Add one geom c + geom_density(kernel = "gaussian")
fill, group, linetype, size, weight shape, size
function per layer.
x, y, alpha, color, fill, group, linetype, size, weight
aesthetic mappings data geom
c + geom_dotplot()
maps
qplot(x = cty, y = hwy, data = mpg, geom = “point") x, y, alpha, color, fill data <- [Link](murder = USArrests$Murder,
Creates a complete plot with given data, geom, and discrete x , discrete y state = tolower(rownames(USArrests)))
mappings. Supplies many useful defaults. c + geom_freqpoly() x, y, alpha, color, group, g <- ggplot(diamonds, aes(cut, color)) map <- map_data("state")
linetype, size k <- ggplot(data, aes(fill = murder))
last_plot() Returns the last plot g + geom_count(), x, y, alpha, color, fill, shape,
c + geom_histogram(binwidth = 5) x, y, alpha, k + geom_map(aes(map_id = state), map = map)
ggsave("[Link]", width = 5, height = 5) Saves last plot color, fill, linetype, size, weight size, stroke + expand_limits(x = map$long, y = map$lat),
as 5’ x 5’ file named "[Link]" in working directory. map_id, alpha, color, fill, linetype, size
Matches file type to file extension. c2 + geom_qq(aes(sample = hwy)) x, y, alpha,
color, fill, linetype, size, weight
THREE VARIABLES
seals$z <- with(seals, sqrt(delta_long^2 + delta_lat^2))l <- ggplot(seals, aes(long, lat))
discrete l + geom_contour(aes(z = z))
l + geom_raster(aes(fill = z), hjust=0.5, vjust=0.5,
d <- ggplot(mpg, aes(fl)) x, y, z, alpha, colour, group, linetype,
interpolate=FALSE)
size, weight x, y, alpha, fill
d + geom_bar()
x, alpha, color, fill, linetype, size, weight l + geom_tile(aes(fill = z)), x, y, alpha, color, fill,
linetype, size, width
RStudio® is a trademark of RStudio, Inc. • CC BY SA RStudio • info@[Link] • 844-448-1212 • [Link] • Learn more at [Link] • ggplot2 3.1.0 • Updated: 2018-12
Figura 14. Cartão de referência dos recursos do ggplot2.
Walmes Zeviani · UFPR Visualização de dados com ggplot2 34
Stats An alternative way to build a layer Scales Coordinate Systems Faceting
A stat builds new variables to plot (e.g., count, prop). Scales map data values to the visual values of an r <- d + geom_bar() Facets divide a plot into
fl cty cyl aesthetic. To change a mapping, add a new scale. r + coord_cartesian(xlim = c(0, 5))
subplots based on the
xlim, ylim
values of one or more
+ =
x ..count.. (n <- d + geom_bar(aes(fill = fl))) The default cartesian coordinate system discrete variables.
aesthetic prepackaged scale-specific r + coord_fixed(ratio = 1/2)
scale_ to adjust scale to use arguments ratio, xlim, ylim
t <- ggplot(mpg, aes(cty, hwy)) + geom_point()
data stat geom coordinate plot Cartesian coordinates with fixed aspect ratio
x = x ·
system n + scale_fill_manual( between x and y units
y = ..count.. values = c("skyblue", "royalblue", "blue", “navy"), r + coord_flip()
t + facet_grid(cols = vars(fl))
Visualize a stat by changing the default stat of a geom limits = c("d", "e", "p", "r"), breaks =c("d", "e", "p", “r"), xlim, ylim
facet into columns based on fl
name = "fuel", labels = c("D", "E", "P", "R")) Flipped Cartesian coordinates
function, geom_bar(stat="count") or by using a stat t + facet_grid(rows = vars(year))
r + coord_polar(theta = "x", direction=1 )
facet into rows based on year
function, stat_count(geom="bar"), which calls a default range of title to use in labels to use breaks to use in theta, start, direction
geom to make a layer (equivalent to a geom function). values to include legend/axis in legend/axis legend/axis
in mapping Polar coordinates t + facet_grid(rows = vars(year), cols = vars(fl))
Use ..name.. syntax to map stat variables to aesthetics. r + coord_trans(ytrans = “sqrt")
facet into both rows and columns
GENERAL PURPOSE SCALES xtrans, ytrans, limx, limy
t + facet_wrap(vars(fl))
Transformed cartesian coordinates. Set xtrans and wrap facets into a rectangular layout
geom to use stat function geommappings ytrans to the name of a window function.
Use with most aesthetics
i + stat_density2d(aes(fill = ..level..), Set scales to let axis limits vary across facets
scale_*_continuous() - map cont’ values to visual ones π + coord_quickmap()
geom = "polygon") 60
variable created by stat scale_*_discrete() - map discrete values to visual ones π + coord_map(projection = "ortho", t + facet_grid(rows = vars(drv), cols = vars(fl),
lat
scale_*_identity() - use data values as visual ones orientation=c(41, -74, 0))projection, orienztation, scales = "free")
xlim, ylim x and y axis limits adjust to individual facets
c + stat_bin(binwidth = 1, origin = 10)
scale_*_manual(values = c()) - map discrete values to long
Map projections from the mapproj package
x, y | ..count.., ..ncount.., ..density.., ..ndensity.. manually chosen visual ones (mercator (default), azequalarea, lagrange, etc.) "free_x" - x axis limits adjust
scale_*_date(date_labels = "%m/%d"), date_breaks = "2 "free_y" - y axis limits adjust
c + stat_count(width = 1) x, y, | ..count.., ..prop.. weeks") - treat data values as dates.
c + stat_density(adjust = 1, kernel = “gaussian")
Set labeller to adjust facet labels
scale_*_datetime() - treat data x values as date times.
x, y, | ..count.., ..density.., ..scaled..
e + stat_bin_2d(bins = 30, drop = T)
Use same arguments as scale_x_date(). See ?strptime for
label formats. Position Adjustments t + facet_grid(cols = vars(fl), labeller = label_both)
fl: c fl: d fl: e fl: p fl: r
x, y, fill | ..count.., ..density.. Position adjustments determine how to arrange geoms t + facet_grid(rows = vars(fl),
X & Y LOCATION SCALES that would otherwise occupy the same space. labeller = label_bquote(alpha ^ .(fl)))
e + stat_bin_hex(bins=30) x, y, fill | ..count.., ..density..
Use with x or y aesthetics (x shown here) ↵c ↵d ↵e ↵p ↵r
e + stat_density_2d(contour = TRUE, n = 100)
s <- ggplot(mpg, aes(fl, fill = drv))
x, y, color, size | ..level.. scale_x_log10() - Plot x on log10 scale
s + geom_bar(position = "dodge")
Labels
e + stat_ellipse(level = 0.95, segments = 51, type = "t") scale_x_reverse() - Reverse direction of x axis
scale_x_sqrt() - Plot x on square root scale Arrange elements side by side
l + stat_contour(aes(z = z)) x, y, z, order | ..level.. s + geom_bar(position = "fill")
Stack elements on top of one another,
t + labs( x = "New x axis label", y = "New y axis label",
l + stat_summary_hex(aes(z = z), bins = 30, fun = max)
COLOR AND FILL SCALES (DISCRETE) normalize height
x, y, z, fill | ..value.. title ="Add a title above the plot",
n <- d + geom_bar(aes(fill = fl)) e + geom_point(position = "jitter")
Use scale functions
subtitle = "Add a subtitle below title",
to update legend
l + stat_summary_2d(aes(z = z), bins = 30, fun = mean)
Add random noise to X and Y position of each
n + scale_fill_brewer(palette = "Blues")
element to avoid overplotting caption = "Add a caption below plot", labels
x, y, z, fill | ..value.. For palette choices: <aes> = "New <aes>
<AES> <AES> legend title")
A
RColorBrewer::[Link]() e + geom_label(position = "nudge")
f + stat_boxplot(coef = 1.5) x, y | ..lower..,
B Nudge labels away from points
t + annotate(geom = "text", x = 8, y = 9, label = "A")
..middle.., ..upper.., ..width.. , ..ymin.., ..ymax.. n + scale_fill_grey(start = 0.2, end = 0.8,
[Link] = "red") geom to place manual values for geom’s aesthetics
f + stat_ydensity(kernel = "gaussian", scale = “area") x, y | s + geom_bar(position = "stack")
..density.., ..scaled.., ..count.., ..n.., ..violinwidth.., ..width.. Stack elements on top of one another
COLOR AND FILL SCALES (CONTINUOUS)
e + stat_ecdf(n = 40) x, y | ..x.., ..y..
e + stat_quantile(quantiles = c(0.1, 0.9), formula = y ~
o <- c + geom_dotplot(aes(fill = ..x..)) Each position adjustment can be recast as a function with
manual width and height arguments Legends
log(x), method = "rq") x, y | ..quantile.. o + scale_fill_distiller(palette = "Blues") s + geom_bar(position = position_dodge(width = 1)) n + theme([Link] = "bottom")
e + stat_smooth(method = "lm", formula = y ~ x, se=T,
Place legend at "bottom", "top", "left", or "right"
level=0.95) x, y | ..se.., ..x.., ..y.., ..ymin.., ..ymax.. o + scale_fill_gradient(low="red", high="yellow") n + guides(fill = "none")
Themes
Set legend type for each aesthetic: colorbar, legend, or
ggplot() + stat_function(aes(x = -3:3), n = 99, fun = o + scale_fill_gradient2(low="red", high=“blue", none (no legend)
dnorm, args = list(sd=0.5)) x | ..x.., ..y.. mid = "white", midpoint = 25) n + scale_fill_discrete(name = "Title",
labels = c("A", "B", "C", "D", "E"))
e + stat_identity([Link] = TRUE) r + theme_bw()
r + theme_classic() Set legend title and labels with a scale function.
o + scale_fill_gradientn(colours=[Link](6)) White background
ggplot() + stat_qq(aes(sample=1:100), dist = qt, Also: rainbow(), [Link](), [Link](), with grid lines r + theme_light()
dparam=list(df=5)) sample, x, y | ..sample.., ..theoretical..
Zooming
[Link](), RColorBrewer::[Link]() r + theme_gray()
r + theme_linedraw()
e + stat_sum() x, y, size | ..n.., ..prop.. Grey background
(default theme) r + theme_minimal()
e + stat_summary([Link] = "mean_cl_boot") SHAPE AND SIZE SCALES Minimal themes
r + theme_dark()
r + theme_void()
Without clipping (preferred)
h + stat_summary_bin(fun.y = "mean", geom = "bar") p <- e + geom_point(aes(shape = fl, size = cyl)) dark for contrast
p + scale_shape() + scale_size() Empty theme t + coord_cartesian(
e + stat_unique() xlim = c(0, 100), ylim = c(10, 20))
p + scale_shape_manual(values = c(3:7))
With clipping (removes unseen data points)
t + xlim(0, 100) + ylim(10, 20)
p + scale_radius(range = c(1,6))
p + scale_size_area(max_size = 6) t + scale_x_continuous(limits = c(0, 100)) +
scale_y_continuous(limits = c(0, 100))
RStudio® is a trademark of RStudio, Inc. • CC BY SA RStudio • info@[Link] • 844-448-1212 • [Link] • Learn more at [Link] • ggplot2 3.1.0 • Updated: 2018-12
Figura 15. Cartão de referência dos recursos do ggplot2.
Walmes Zeviani · UFPR Visualização de dados com ggplot2 35