Git Product home page Git Product logo

Comments (2)

EllaKaye avatar EllaKaye commented on June 12, 2024

Ooh, this is an interesting idea! I'm about to use {palettes} to make a package with my university's brand colours (The University of Warwick), and was planning on adding a theme_warwick() function to improve the standard look of plots (like Cara Thompson demonstrates in this talk. I hadn't thought about passing a palette argument to it, but it would be an interesting way to generalise it. If I head down that route and it works well, maybe it could be a starting point for something that would work here. Can you say more about what you had in mind for how this would work?

from palettes.

mccarthy-m-g avatar mccarthy-m-g commented on June 12, 2024

Goal

I’m pretty open on what this will look like, but my original thought was a function like:

theme_palette(palette, …)

Or maybe several theme_palette_x() functions would be nicer, one for each of the theme types provided by ggplot2 (e.g., grey, classic, minimal, etc.).

Regardless, the basic idea is that you supply a palette to change the colour of multiple elements of a theme together. It’s a convenience function so you don’t need to write out all the theme() and element_x() code just to change some colours.

Example

ggprism does this, but there they provide premade palettes and the user just picks the one they want by name: https://cran.r-project.org/web/packages/ggprism/vignettes/themes.html#theme-palettes. I wanted to generalize this idea—where the user provides a palette and the function “smartly” colours elements based on the number of colours in the palette.

For example, if a palette had one colour, then that colour would be applied to all theme elements (axis lines, ticks, etc.); but if it had more than one colour then colours would be applied more selectively to certain elements (maybe the first colour would go to axis elements, the second to gridlines, or something like that). Which elements get grouped together and given the same colour would be an opinionated decision. There would also be an upper limit on the maximum number of colours from a palette that would actually be used, probably in the 2-4 range.

API

I think it would be a good idea to handle the background and text colour separately from the palette argument with (optional?) bg and fg arguments. If they’re optional, they’d default to “white” and “black”, respectively. These arguments would accept character strings or classed colour vectors.

Other inspiration

thematic provides an interesting approach to overriding ggplot themes based on bootstrap theme elements. I haven’t dug into how it works, but some of the ideas used there might work nicely for deciding which theme elements to group together with the same colour, a max colour limit, etc.

It also works with custom themes: https://rstudio.github.io/thematic/articles/custom.html

It may also mean a theme_palette() function is somewhat redundant in the scope of things 🤷‍♂️


Cool talk! And let me know how your package goes 😄

from palettes.

Related Issues (20)

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.