Comments (2)
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.
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)
- Add American spelling "color" alias functions
- Fix asciicast output in README
- Organize pkgdown reference page
- Add tests
- New/Better Hex Sticker HOT 1
- Add `create_` function HOT 1
- purrr 1.0 changes
- Set environment variable for number of ANSI colours
- What is the `pal_brewer` function? HOT 2
- Export lighten and darken functions? HOT 5
- v0.2.0
- Bivariate colour interpolation (`pal_ramp_bibariate()`)
- Option to change colour preview symbol HOT 1
- New Vignette: Colour previews in R Markdown and Quarto HOT 1
- Pretty print colour names in colour vectors
- Add info text to `validate_colour()` error message
- Add compact `print_style` option
- Add American spelling for `list_colour_symbols()`
- Release palettes 0.2.0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from palettes.