GGFormula addons

A number of methods from the ggformula package can be used to provide additions to a graph. We’ll look at some of these here.

gf_labs

gf_labs can be used for setting various labels on a graph.

gf_lims

gf_lims can be used to control the limits on the x and/or y axis, by specifying a start and/or an end for each direction.

gf_abline, gf_hline, gf_vline

gf_abline, gf_hline and gf_vline can be used to add specific lines to a graph (horizontal, vertical or with arbitrary slope and intercept).

gf_facet_grid and gf_facet_wrap

gf_facet_grid and gf_facet_wrap allow us to create multiple panels depending on the option provided by a categorical variable. The _grid version allows one variable on each direction, while the _wrap variant allows a single variable, and it will wrap on as many lines as needed.

gf_lm and gf_smooth

gf_lm and gf_smooth can be used for adding linear regression lines and smoothers to scatterplots.

gf_text

gf_text can be used to add text to specific locations. It can be a stand-alone graph or just an addon to a graph.

guns %>% gf_point(mort_rate~own_rate, size=2, color=~hdi, alpha=0.7) %>%
    gf_text(mort_rate~own_rate, label=~country, size=4, color="black", alpha=0.5, nudge_y=0.3)

gf_theme

gf_theme can be used to set the overall theme for the graph, especially the background and axis colors etc. This can be one of the standard themes, and/or specific changes.

gf_refine and scales

gf_refine can be used, in combination with a number of “scale” functions, to determine what colors and other attributes will be used for mapped parameters. These functions take the form: scale_xxx_yyy where the xxx part is the kind of attribute that we want to map (color, fill, shape, alpha etc) and the yyy part is the kind of functions we want to use for it.

For colors, a common solution is to use the ColorBrewer package and choose one of the provided palettes.

For the axes, the scale_x_..... and scale_y_.... functions offer some standard transformation (e.g. logarithmic).