Giter Club home page Giter Club logo

rssthemes's Introduction

R package for styling graphics for RSS publications.

The package is currently available on GitHub and you can install it with:

remotes::install_github("nrennie/RSSthemes")

You can then load the package using:

library(RSSthemes)

Colour palettes

There are currently three palettes available in {RSSthemes}, although we hope to add more in the future.

Using palettes with {ggplot2}

Let’s set up a basic data set.

library(ggplot2)
plot_df <- data.frame(x = LETTERS[1:4],
                      y = 1:4)

Single colour charts

If all of the bars, lines, points, etc. should have the same colour, you can set either the fill or colour arguments to have one of the RSS colours. The options are: signif_red, signif_blue, signif_green, signif_orange, or signif_yellow.

ggplot(data = plot_df,
       mapping = aes(x = x, y = y)) +
  geom_col(fill = signif_yellow)

Qualitative palettes

For working with qualitative (discrete) data, the best palette to use is "signif_qual". This palette currently only contains four colours.

Discrete (fill) scale: scale_fill_rss_d()

ggplot(data = plot_df,
       mapping = aes(x = x, y = y, fill = x)) +
  geom_col() +
  scale_fill_rss_d(palette = "signif_qual")

Discrete (colour) scale: scale_colour_rss_d()

ggplot(data = plot_df,
       mapping = aes(x = x, y = y, colour = x)) +
  geom_point(size = 4) +
  scale_colour_rss_d(palette = "signif_qual")

Sequential palettes

For working with sequential (continuous) data, the best palette to use is "signif_seq".

Continuous (fill) scale: scale_fill_rss_c()

ggplot(data = plot_df,
       mapping = aes(x = x, y = y, fill = y)) +
  geom_col() +
  scale_fill_rss_c(palette = "signif_seq")

Continuous (colour) scale: scale_colour_rss_c()

ggplot(data = plot_df,
       mapping = aes(x = x, y = y, colour = y)) +
  geom_point(size = 4) +
  scale_colour_rss_c(palette = "signif_seq")

Diverging palettes

For working with diverging (continuous) data, the best palette to use is "signif_div".

Continuous (fill) scale: scale_fill_rss_c()

ggplot(data = plot_df,
       mapping = aes(x = x, y = y, fill = y)) +
  geom_col() +
  scale_fill_rss_c(palette = "signif_div")

If you want to centre the diverging scale around a different value, you can alternatively pass the pre-defined colours into scale_fill_gradient2() from {ggplot2}:

ggplot(data = plot_df,
       mapping = aes(x = x, y = y, fill = y)) +
  geom_col() +
  scale_fill_gradient2(low = signif_red, high = signif_blue, midpoint = 2)

Using palettes with base R

If all of the bars, lines, points, etc. should have the same colour, you can set col arguments to have one of the RSS colours. The options are: signif_red, signif_blue, signif_green, signif_orange, or signif_yellow.

barplot(table(mtcars$gear), col = signif_blue)

You can use the set_rss_palette() function to change the default colours used in base R plotting:

set_rss_palette("signif_qual")
plot(1:4, 1:4, col=1:4, pch=19, cex=3, xlab="", ylab="")

Run palette("default") to reset to original base R colours.

Theme functions

Theme functions style the non-data elements of plots, e.g. fonts, text colour, or background colour.

Using themes with {ggplot2}

Apply styling to plots made with {ggplot2} using the theme_significance() function:

ggplot(data = plot_df,
       mapping = aes(x = x, y = y, fill = x)) +
  geom_col() +
  labs(title = "My Significance Plot",
       subtitle = "Some longer sentence explaining what is happening in the chart.",
       caption = "Source: name of data source") +
  scale_fill_rss_d(palette = "signif_qual") +
  theme_significance()

Using themes with base R

Apply styling to plots made with base R using the set_signif_par() function. We also recommend adding reference lines using the abline() function:

set_signif_par()
plot(1:4, 1:4, col=1:4, pch=19, cex=3, xlab="", ylab="",
     main = "My Significance Plot",
     sub = "Source: data source")
abline(h=1:4, v=1:4, col = "lightgrey")

rssthemes's People

Contributors

nrennie avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.