library(dplyr) library(simplevis) library(palmerpenguins) library(ggplot2) library(patchwork) set.seed(123456789)
simplevis is a package of
leaflet wrapper functions that aims to make visualisation easier with less brainpower required.
simplevis supports many visualisation family types.
Each visualisation family generally has four functions.
This is based on whether or not a visualisation is to be:
The premise is that these are the most common types of visualisation for each of the families.
All arguments for variables are required unqutoted and follow an
*_var format (i.e.
For example, code below shows these combinations with code and output for the
gg_point_col_facet(penguins, x_var = bill_length_mm, y_var = body_mass_g, col_var = sex, facet_var = species)
simplevis plots are designed to work and look clean with the bare minimum of code.
However, there is plenty of flexibility to customise.
Change the colour palette by supplying a vector of hex code colours to the
gg_point_col(penguins, x_var = bill_length_mm, y_var = body_mass_g, col_var = species, pal = c("#da3490", "#9089fa", "#47e26f"))
Numerous colour palettes are available from the
simplevis also supports easy colouring of numeric variables for
gg_stars*() (and equivalent leaflet functions).
The col_method argument allows you to specify the method for colouring with a default of continuous.
gg_point_col(penguins, x_var = bill_length_mm, y_var = body_mass_g, col_var = flipper_length_mm, col_method = "continuous", subtitle = "col_method = 'continuous'")
Other methods available are
quantile, you can fine-tune using the
You can also adjust the opacity of objects in the visualisation through the
Refer to the colour article for further information.
You can adjust the theme of any
simplevis plot by providing a
ggplot2 theme to the
gg_point_col(penguins, x_var = bill_length_mm, y_var = body_mass_g, col_var = species, title = "A nice title", subtitle = "And a subtitle", theme = ggplot2::theme_grey())
You can also create your own quick themes with the
custom_theme <- gg_theme( pal_body = "white", pal_title = "white", pal_subtitle = "white", pal_background = c("#232323", "black"), pal_gridlines = "black", gridlines_h = TRUE, gridlines_v = TRUE) gg_point_col(penguins, species, x_var = bill_length_mm, y_var = body_mass_g, theme = custom_theme)
Refer to the themes article for further information.
There are lots of arguments available to modify the defaults.
In general, arguments have consistent prefixes based on
facet_*, and as such the autocomplete can help identify what you need.
Some examples of transformations available are:
*_na_rmto quickly not include NA observations
*_labelsto adjust labels for any x, y, col or facet scale
*_zeroto start at zero for numeric x or y scales
*_breaks_nfor the number of numeric bins of breaks for the x, y or col scale to aim for
*_revto reverse the order of categorical x, y or col scales in bars
*_expandto add padding to an x or y scale.
*_balanceto balance a numeric scale, so that zero is in the centre
col_legend_noneto turn the legend off.
plot_data <- storms %>% group_by(year, status) %>% summarise(wind = mean(wind)) gg_line_col(plot_data, x_var = year, y_var = wind, col_var = status, x_breaks_n = 10, x_labels = function(x) stringr::str_sub(x, 3, 4), y_labels = scales::label_dollar(accuracy = 1), col_labels = c("H", "TD", "TS"), y_zero = TRUE, y_breaks_n = 10, y_expand = ggplot2::expansion(add = c(0, 10)))