Skip to content

Update README.Rmd to align with changes made to README.md #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
90 changes: 44 additions & 46 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -1,52 +1,54 @@
---
output:
md_document:
variant: markdown_github
variant: gfm
toc: true
toc_depth: 2
pandoc_args: ["--wrap=none"]
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r echo=FALSE}
```{r startup, echo=FALSE, messages=FALSE, warnings=FALSE}
suppressPackageStartupMessages(library(ggplot2))
suppressPackageStartupMessages(library(gridExtra))
example_plot <- ggplot(diamonds, aes(price, fill = factor(cut))) +
geom_histogram(binwidth = 850) +
xlab('Price (USD)') +
ylab('Count') +
scale_x_continuous(label = function(x) paste0(x / 1000, 'k')) +
theme(legend.position = 'none') +
scale_y_continuous(label = function(x) format(x, big.mark = ",", scientific = FALSE))
xlab("Price (USD)") +
ylab("Count") +
scale_x_continuous(label = function(x) paste0(x / 1000, "k")) +
theme(legend.position = "none") +
scale_y_continuous(label = function(x) format(x, big.mark = ",",
scientific = FALSE))
library(ggthemr)
source('scripts/preview_theme.R')
source('scripts/preview_layout.R')
source("scripts/preview_theme.R")
source("scripts/preview_layout.R")
```

ggthemr
========================================================
**[Mikata Project](https://github.com/Mikata-Project) took over ggthemr and will be the primary maintainer of this wonderful package.** We would like to thank [\@cttobin](https://github.com/cttobin) for creating this package. We also appreciate that he agreed to pass the repo ownership to Mikata Project. The Mikata Team plans to resolve backlog issues and make `ggthemr` available on CRAN as the first step.

# ggthemr

Themes for ggplot2. The idea of this package is that you can just set the theme and then forget about it. You shouldn't have to change any of your existing code. There are several parts to a theme:

* Colour palette for the background, axes, gridlines, text etc.
* Layout of axes lines and gridlines.
* Spacing around plot and between elements (i.e. axes titles to axes lines etc). You can set the spacing to determine how compact or spread out a plot is.
* Text size.
- Colour palette for the background, axes, gridlines, text etc.
- Layout of axes lines and gridlines.
- Spacing around plot and between elements (i.e. axes titles to axes lines etc). You can set the spacing to determine how compact or spread out a plot is.
- Text size.

There are a number of preset palettes and layouts, and methods to create your own colour schemes.


Installation
-------------------------
## Installation

This package is still under development, but can be installed using [devtools](http://cran.r-project.org/web/packages/devtools/index.html).

```{r eval=FALSE}
devtools::install_github('cttobin/ggthemr')
devtools::install_github('Mikata-Project/ggthemr')
```

Usage
-------------------------
*We plan to submit to CRAN soon, but that is currently blocked by an upstream issue now*

## Usage

To just set the colour scheme:

Expand All @@ -60,8 +62,11 @@ That's it. Any ggplot you create from then on will have the theme applied. You c
ggthemr_reset()
```

Palettes
-------------------------
## Known issues

In some instances, i.e. when plotting the `diamonds` dataset, the ggthemr colour is not respected and a viridis one is used instead.

## Palettes

The palette determines the colours of everything in a plot including the background, layers, gridlines, title text, axes lines, axes text and axes titles. The *swatch* is the the name given to the set of colours strictly used in styling the geoms/layer elements (e.g. the points in `geom_point()`, bars in `geom_bar()` etc.). At least six colours have been supplied in each palette's swatch.

Expand Down Expand Up @@ -190,12 +195,11 @@ ggthemr('solarized', spacing = 0.5, type = 'inner')
preview_theme()
```

Custom Palettes
-------------------------
## Custom Palettes

`define_palette()` lets you make your own themes that can be passed to `ggthemr()` just like any of the palettes above. Here's an example of a (probably ugly) palette using random colours:

``` {r fig.width=5.5, fig.height=4.5}
```{r fig.width=5.5, fig.height=4.5}
# Random colours that aren't white.
set.seed(12345)
random_colours <- sample(colors()[-c(1, 253, 361)], 10L)
Expand All @@ -208,14 +212,12 @@ ugly <- define_palette(
ggthemr(ugly)

example_plot + ggtitle(':(')

```

You can define all elements of a palette using `define_palette()` including colours for the background, text, axes lines, swatch and gradients.


Layouts
-------------------------
## Layouts

The layout of a theme controls the appearance and position of the axes, gridlines and text. Some folk prefer both major and minor gridlines, others prefer none or something in between.

Expand Down Expand Up @@ -254,8 +256,7 @@ ggthemr('grape', layout = 'scientific', spacing = 0.5)
preview_layout()
```

Spacing
-------------------------
## Spacing

Plot margins and space between axes titles and lines etc. is controlled with the *spacing* parameter. Lower values will make plots more compact, higher values will give them more padding. Compare the plots below where the spacing has been set to 0, 1 and 2 respectively.

Expand All @@ -274,8 +275,7 @@ ggthemr('earth', spacing = 2, type = 'outer')
preview_layout()
```

Type
-------------------------
## Type

The *type* parameter can be set to either *inner* or *outer*. When *inner*, the background colour of a plot will not extend past the plot area. *outer* will colour the entire plot and background.

Expand All @@ -290,8 +290,7 @@ example_plot
```


Tweaking Themes
-------------------------
## Tweaking Themes

Squinting at a chart? Low on printer ink? ggthemr includes some methods to tweak charts to make them lighter or darker. Here's a standard theme:

Expand All @@ -309,15 +308,14 @@ example_plot

The second parameter to `darken_swatch()` controls the degree to which the colours are made darker. Full list of methods with similar functionality:

* `darken_swatch()` / `lighten_swatch()`: darker/lighter swatch colours.
* `darken_gradient()` / `lighten_gradient()`: darker/lighter gradient colours.
* `darken_palette()` / `lighten_palette()`: darker/lighter everything.
- `darken_swatch()` / `lighten_swatch()`: darker/lighter swatch colours.
- `darken_gradient()` / `lighten_gradient()`: darker/lighter gradient colours.
- `darken_palette()` / `lighten_palette()`: darker/lighter everything.

I'll add methods to darken/lighten the axes lines and text soon too.


Plot Adjustments
-------------------------
## Plot Adjustments

Most of the time you'll probably just want to set the theme and not worry about it. There may be times though where you'll want to make some small adjustment, or manually change what items appear as what colour in a plot.

Expand Down Expand Up @@ -345,26 +343,26 @@ mpg_plot + scale_fill_manual(values = rev(to_swap))

**Note:** the first colour in a swatch is a special one. It is reserved for outlining boxplots, text etc. So that's why the second and third colours were swapped.

A note about theme setting
--------------------------
## A note about theme setting
ggthemr does three different things while setting a theme.

1. It updates the default ggplot2 theme with the specified ggthemr theme by using the `ggplot2::theme_set()` function.
2. It modifies the aesthetic defaults for all geoms using the `ggplot2::update_geom_defaults()` function.
3. It creates functions for all the different scales in the global environment.

In case, if you do not want to set the theme this way, use the `set_theme = FALSE` option while using the `ggthemr` function. An example of setting theme, geom aesthetic defaults and scales manually:

```{r}
ggthemr_reset()
dust_theme <- ggthemr('dust', set_theme = FALSE)
example_plot
example_plot + dust_theme$theme
example_plot + dust_theme$theme + dust_theme$scales$scale_fill_discrete()
do.call(what = ggplot2::update_geom_defaults, args = dust_theme$geom_defaults$new$bar)
#example_plot + dust_theme$theme + dust_theme$scales$scale_fill_discrete()
do.call(what = ggplot2::update_geom_defaults,
args = dust_theme$geom_defaults$new$bar)
ggplot(diamonds, aes(price)) + geom_histogram(binwidth = 850) + dust_theme$theme
```


License
-------
## License
Released under GPL-3.
Loading