knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" ) library(tidyverse) library(ggIFS)
The goal of ggIFS is to quickly create IFS-style graphs with ggplot2.
For those not familiar with the structure of ggplot2, graph theme and colours are defined separately. Theme refers to everything on the graph that is not the data - i.e. the axis ticks and lines, the plot background, the title, etc. Colours are applied separately, typically by using scale_fill_manual() or scale_colour_manual().
To make things even more confusing, there are two types of ways to colour a graph: 'fill' and 'colour'. Fill is for things you want to fill, such as bar graphs and area graphs, and colour is for things you want to outline, such as line graphs and scatter graphs. I'm not sure why it was defined separately, but it means that if you add a colour to a bar graph, it will only affect the outline of the bar graph.
You can install the development version of ggIFS from GitHub with:
# install.packages("devtools") devtools::install_github("vedanthnair/ggIFS")
This is an example which applies the IFS theme and colour to a bar plot. Iris is a default dataset that comes with most distributions of R.
# Creating an example dataframe, which has the mean variable for each species iris2 <- iris %>% group_by(Species) %>% summarize(across(.cols = everything(), mean, na.rm = T)) %>% pivot_longer(cols = !Species) %>% arrange(name) iris2
Without putting in any arguments, scale_fill_ifs() (we are using fill because we want a bar chart), will automatically apply the IFS standard colour palette (mid-primary colours).
ggplot(iris2) + geom_bar(aes(x = Species, y = value, fill = name), stat = "identity") + theme_ifs() + scale_fill_ifs()
We can choose a custom palette, e.g. greens. Palettes can be greens, greys, yellows, reds, blues, purples.
ggplot(iris2) + geom_bar(aes(x = Species, y = value, fill = name), stat = "identity") + theme_ifs() + scale_fill_ifs(palette = "greens")
We can choose custom colour values, using the 'values' argument. The potential values are dark_X_2, dark_X_1, mid_X, light_X_1, light_X_2, light_X_3, substituting X for green, grey, yellow, red, blue or purple (following the IFS naming convention.)
ggplot(iris2) + geom_bar(aes(x = Species, y = value, fill = name), stat = "identity") + theme_ifs() + scale_fill_ifs(values = c("dark_green_2", "dark_green_1", "mid_yellow", "mid_red"))
You can also add gradients, in which case the palette or user-specified values are taken as start, end and mid points of the gradient.
ggplot(iris) + geom_point(aes(x = Sepal.Length, y = Sepal.Width, col = Petal.Width)) + theme_ifs() + scale_colour_ifs(palette = "greens", gradient = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.