The goal of tools42 is to make life easier for folks at ideas42 who are doing analytical work. While this is a work in progress, our goal is to include features like:
ggplot2
You can install the development version from GitHub with:
# install.packages("devtools")
devtools::install_github("ideas42/tools42")
This is a basic example which shows you how to solve a common problem: plotting your data. Let’s start with a scatterplot and histogram.
library(tools42)
## Plotting a histogram of penguin bill length
viz_hist(penguins, bill_length_mm) +
theme_42()
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> Warning: Removed 2 rows containing non-finite values (stat_bin).
## Simple scatterplot
viz_scatter(penguins, bill_length_mm, flipper_length_mm) +
theme_42()
#> Warning: Removed 2 rows containing missing values (geom_point).
As you saw in the last section, we also have some themes. These are
designed to make your plots looks nicer, and so far there’s two of them.
The first, theme_42
, is a simple, clean, theme that minimizes clutter.
library(ggplot2)
viz_scatter(penguins, bill_length_mm, flipper_length_mm) +
labs(title = "This is a sample plot",
subtitle = "And this is the subtitle") +
theme_42()
#> Warning: Removed 2 rows containing missing values (geom_point).
We also have
a brighter, warmer theme. To use it, just add
theme_42_bright
to your
call. This can be used with the helper functions viz_*
as well as with
regular ggplot
calls:
ggplot(penguins, aes(bill_length_mm, flipper_length_mm)) +
geom_point() +
labs(title = "This is a sample plot",
subtitle = "And this is the subtitle") +
theme_42_bright()
#> Warning: Removed 2 rows containing missing values (geom_point).
Lastly, we’ve created some color schemes for you. There’s two palettes:
i42
, and i42_bright
. To visualize them, just use the palette_42
function.
palette_42("i42_bright")
Here’s what it looks like when we combine it with a previous plot.
ggplot(penguins, aes(bill_length_mm, flipper_length_mm, color = species)) +
geom_point() +
labs(title = "This is a sample plot",
subtitle = "And this is the subtitle") +
theme_42_bright() +
scale_color_manual(values = palette_42("i42_bright"))
#> Warning: Removed 2 rows containing missing values (geom_point).
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.