library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.5.3
library(ggindex)
cars <- mtcars
cars$model <- rownames(cars)
cars$rank <- rank(-cars$mpg, ties.method = "first")The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.
This article changes how the markers and their numbers look, and shows how they follow themes and facets. For the basics, see Get started.
library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.5.3
library(ggindex)
cars <- mtcars
cars$model <- rownames(cars)
cars$rank <- rank(-cars$mpg, ties.method = "first")The markers use the standard colour, fill, shape, size, stroke and alpha aesthetics, so they work with the usual ggplot2 scales. Here the most efficient car of each cylinder class is filled by class.
cars$best <- cars$mpg == ave(cars$mpg, cars$cyl, FUN = max)
ggplot(cars, aes(wt, mpg)) +
geom_point(colour = "grey60") +
geom_focus(
aes(label = rank, focus = best, info = model, fill = factor(cyl)),
shape = 22,
size = 7
) +
scale_fill_brewer("Cylinders", palette = "Set2") +
scale_info_discrete("Best in class") +
theme_minimal()The numbers take the family and fontface aesthetics and the text.colour and text.size parameters. By default they use the marker’s colour. The legend keys show the same style.
ggplot(cars, aes(wt, mpg)) +
geom_point(colour = "grey60") +
geom_focus(
aes(label = rank, focus = rank <= 5, info = model),
fill = "grey20",
text.colour = "white",
fontface = "bold"
) +
theme_minimal()Without other settings, markers are filled with the theme’s paper colour and drawn with its ink colour, so they follow the theme.
ggplot(cars, aes(wt, mpg)) +
geom_point(colour = "grey50") +
geom_focus(aes(label = rank, focus = rank <= 5, info = model)) +
theme_minimal(ink = "white", paper = "grey15")Focus points are drawn in the panel they fall in, and a panel without focus points shows only the other layers. The three most efficient cars all have four cylinders.
ggplot(cars, aes(wt, mpg)) +
geom_point(colour = "grey60") +
geom_focus(aes(label = rank, focus = rank <= 3, info = model)) +
facet_wrap(vars(cyl), labeller = label_both) +
theme_minimal()These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.