{"id":13401487,"url":"https://github.com/Mikata-Project/ggthemr","last_synced_at":"2025-03-14T07:31:43.354Z","repository":{"id":40450986,"uuid":"13367216","full_name":"Mikata-Project/ggthemr","owner":"Mikata-Project","description":"Themes for ggplot2.","archived":false,"fork":false,"pushed_at":"2022-05-07T19:44:21.000Z","size":24676,"stargazers_count":900,"open_issues_count":13,"forks_count":108,"subscribers_count":36,"default_branch":"master","last_synced_at":"2025-03-11T08:47:28.952Z","etag":null,"topics":["data-visualization","ggplot2","ggplot2-themes","plotting","plotting-in-r","r","rstats","visualization"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mikata-Project.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-10-06T18:50:41.000Z","updated_at":"2025-03-07T07:21:16.000Z","dependencies_parsed_at":"2022-07-12T18:02:20.408Z","dependency_job_id":null,"html_url":"https://github.com/Mikata-Project/ggthemr","commit_stats":null,"previous_names":["cttobin/ggthemr"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mikata-Project%2Fggthemr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mikata-Project%2Fggthemr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mikata-Project%2Fggthemr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mikata-Project%2Fggthemr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mikata-Project","download_url":"https://codeload.github.com/Mikata-Project/ggthemr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243307489,"owners_count":20270262,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-visualization","ggplot2","ggplot2-themes","plotting","plotting-in-r","r","rstats","visualization"],"created_at":"2024-07-30T19:01:03.333Z","updated_at":"2025-03-14T07:31:43.347Z","avatar_url":"https://github.com/Mikata-Project.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\noutput:\n  md_document:\n    variant: markdown_github\n    toc: true\n    toc_depth: 2\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r echo=FALSE}\nsuppressPackageStartupMessages(library(ggplot2))\nsuppressPackageStartupMessages(library(gridExtra))\nexample_plot \u003c- ggplot(diamonds, aes(price, fill = factor(cut))) +\n  geom_histogram(binwidth = 850) +\n  xlab('Price (USD)') +\n  ylab('Count') +\n  scale_x_continuous(label = function(x) paste0(x / 1000, 'k')) +\n  theme(legend.position = 'none') +\n  scale_y_continuous(label = function(x) format(x, big.mark = \",\", scientific = FALSE))\nlibrary(ggthemr)\nsource('scripts/preview_theme.R')\nsource('scripts/preview_layout.R')\n```\n\nggthemr\n========================================================\n\nThemes 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:\n\n* Colour palette for the background, axes, gridlines, text etc. \n* Layout of axes lines and gridlines.\n* 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.\n* Text size.\n\nThere are a number of preset palettes and layouts, and methods to create your own colour schemes.\n\n\nInstallation\n-------------------------\n\nThis package is still under development, but can be installed using [devtools](http://cran.r-project.org/web/packages/devtools/index.html).\n\n```{r eval=FALSE}\ndevtools::install_github('cttobin/ggthemr')\n```\n\nUsage\n-------------------------\n\nTo just set the colour scheme:\n\n```{r eval=FALSE}\nggthemr('dust')\n```\n\nThat's it. Any ggplot you create from then on will have the theme applied. You can clear the theme and return to ggplot2's default using:\n\n```{r eval=FALSE}\nggthemr_reset()\n```\n\nPalettes\n-------------------------\n\nThe 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. \n\nThere are a wide variety of themes in this package (and more on the way). Some of them serious business... others are deliberately stylish and might not be that good for use in proper publications. \n\n### flat\n\n[Base 16](https://github.com/chriskempson/base16)\n\n```{r fig.width=10, fig.height=6, echo=FALSE}\nggthemr('flat', spacing = 0.5, type = 'inner')\npreview_theme()\n```\n\n### flat dark\n\n[Base 16](https://github.com/chriskempson/base16)\n\n```{r fig.width=10, fig.height=6, echo=FALSE}\nggthemr('flat dark', spacing = 0.5, type = 'inner')\npreview_theme()\n```\n\n### camouflage\n\n```{r fig.width=10, fig.height=6, echo=FALSE}\nggthemr('camouflage', spacing = 0.5, type = 'inner')\npreview_theme()\n```\n\n### chalk\n\n```{r fig.width=10, fig.height=6, echo=FALSE}\nggthemr('chalk', spacing = 0.5, type = 'inner')\npreview_theme()\n```\n\n### copper\n\n```{r fig.width=10, fig.height=6, echo=FALSE}\nggthemr('copper', spacing = 0.5, type = 'inner')\npreview_theme()\n```\n\n### dust\n\n```{r fig.width=10, fig.height=6, echo=FALSE}\nggthemr('dust', spacing = 0.5, type = 'inner')\npreview_theme()\n```\n\n### earth\n\n```{r fig.width=10, fig.height=6, echo=FALSE}\nggthemr('earth', spacing = 0.5, type = 'inner')\npreview_theme()\n```\n\n### fresh\n\n```{r fig.width=10, fig.height=6, echo=FALSE}\nggthemr('fresh', spacing = 0.5, type = 'inner')\npreview_theme()\n```\n\n### grape\n\n```{r fig.width=10, fig.height=6, echo=FALSE}\nggthemr('grape', spacing = 0.5, type = 'inner')\npreview_theme()\n```\n\n### grass\n\n```{r fig.width=10, fig.height=6, echo=FALSE}\nggthemr('grass', spacing = 0.5, type = 'inner')\npreview_theme()\n```\n\n### greyscale\n\n```{r fig.width=10, fig.height=6, echo=FALSE}\nggthemr('greyscale', spacing = 0.5, type = 'inner')\npreview_theme()\n```\n\n### light\n\n```{r fig.width=10, fig.height=6, echo=FALSE}\nggthemr('light', spacing = 0.5, type = 'inner')\npreview_theme()\n```\n\n### lilac\n\n```{r fig.width=10, fig.height=6, echo=FALSE}\nggthemr('lilac', spacing = 0.5, type = 'inner')\npreview_theme()\n```\n\n### pale\n\n```{r fig.width=10, fig.height=6, echo=FALSE}\nggthemr('pale', spacing = 0.5, type = 'inner')\npreview_theme()\n```\n\n### sea\n\n```{r fig.width=10, fig.height=6, echo=FALSE}\nggthemr('sea', spacing = 0.5, type = 'inner')\npreview_theme()\n```\n\n### sky\n\n```{r fig.width=10, fig.height=6, echo=FALSE}\nggthemr('sky', spacing = 0.5, type = 'inner')\npreview_theme()\n```\n\n### solarized\n\n```{r fig.width=10, fig.height=6, echo=FALSE}\nggthemr('solarized', spacing = 0.5, type = 'inner')\npreview_theme()\n```\n\nCustom Palettes\n-------------------------\n\n`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:\n\n``` {r fig.width=5.5, fig.height=4.5}\n# Random colours that aren't white.\nset.seed(12345)\nrandom_colours \u003c- sample(colors()[-c(1, 253, 361)], 10L)\n\nugly \u003c- define_palette(\n  swatch = random_colours,\n  gradient = c(lower = random_colours[1L], upper = random_colours[2L])\n)\n\nggthemr(ugly)\n\nexample_plot + ggtitle(':(')\n\n```\n\nYou can define all elements of a palette using `define_palette()` including colours for the background, text, axes lines, swatch and gradients. \n\n\nLayouts\n-------------------------\n\nThe 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. \n\n### Clean\n\n```{r fig.width=5.5, fig.height=3.5, echo=FALSE}\nggthemr('grape', layout = 'clean', spacing = 0.5)\npreview_layout()\n```\n\n### Clear (default)\n\n```{r fig.width=5.5, fig.height=3.5, echo=FALSE}\nggthemr('grape', layout = 'clear', spacing = 0.5)\npreview_layout()\n```\n\n### Minimal\n\n```{r fig.width=5.5, fig.height=3.5, echo=FALSE}\nggthemr('grape', layout = 'minimal', spacing = 0.5)\npreview_layout()\n```\n\n### Plain\n\n```{r fig.width=5.5, fig.height=3.5, echo=FALSE}\nggthemr('grape', layout = 'plain', spacing = 0.5)\npreview_layout()\n```\n\n### Scientific\n\n```{r fig.width=5.5, fig.height=3.5, echo=FALSE}\nggthemr('grape', layout = 'scientific', spacing = 0.5)\npreview_layout()\n```\n\nSpacing\n-------------------------\n\nPlot 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.\n\n```{r fig.width=5.5, fig.height=3.5, echo=FALSE}\nggthemr('earth', spacing = 0, type = 'outer')\npreview_layout()\n```\n\n```{r fig.width=5.5, fig.height=3.5, echo=FALSE}\nggthemr('earth', spacing = 1, type = 'outer')\npreview_layout()\n```\n\n```{r fig.width=5.5, fig.height=3.5, echo=FALSE}\nggthemr('earth', spacing = 2, type = 'outer')\npreview_layout()\n```\n\nType\n-------------------------\n\nThe *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. \n\n```{r fig.width=5.5, fig.height=3.5, echo=TRUE}\nggthemr('earth', type = 'inner')\nexample_plot\n```\n\n```{r fig.width=5.5, fig.height=3.5, echo=TRUE}\nggthemr('earth', type = 'outer')\nexample_plot\n```\n\n\nTweaking Themes\n-------------------------\n\nSquinting 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:\n\n```{r fig.width=7, fig.height=6, echo=TRUE}\nggthemr('dust')\nexample_plot\n```\n\nMaybe that plot comes out a bit pale looking when you print it. Here's how you can add a bit more contrast to the swatch:\n\n```{r fig.width=7, fig.height=6, echo=TRUE}\ndarken_swatch(amount = 0.3)\nexample_plot\n```\n\nThe second parameter to `darken_swatch()` controls the degree to which the colours are made darker. Full list of methods with similar functionality:\n\n* `darken_swatch()` / `lighten_swatch()`: darker/lighter swatch colours.\n* `darken_gradient()` / `lighten_gradient()`: darker/lighter gradient colours.\n* `darken_palette()` / `lighten_palette()`: darker/lighter everything.\n\nI'll add methods to darken/lighten the axes lines and text soon too. \n\n\nPlot Adjustments\n-------------------------\n\nMost 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.\n\n```{r fig.width=7, fig.height=6, echo=TRUE}\nggthemr('dust')\nmpg_plot \u003c- ggplot(mpg[mpg$drv != '4', ], aes(factor(cyl), cty, fill = drv)) + \n  geom_boxplot() + labs(x = 'Cylinders', y = 'City MPG', fill = 'Drive Type') +\n  theme(legend.position = 'bottom')\nmpg_plot\n```\n\n\nFor some reason you decide you want to change those colours. Front-wheel drive vehicles should be orange. Rear-wheelers should be that red colour. You could change the order of the levels of your fill variable, but you shouldn't have to do that. You just want to switch those colours but you have no idea what they are. `swatch()` will give you the colours in the currently active ggthemr palette. \n\n```{r}\nswatch()\n```\n\nSo you can manually swap the two colours around.\n\n```{r fig.width=7, fig.height=6, echo=TRUE}\nto_swap \u003c- swatch()[2:3]\nmpg_plot + scale_fill_manual(values = rev(to_swap))\n```\n\n**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.\n\nA note about theme setting\n--------------------------\nggthemr does three different things while setting a theme.\n\n1. It updates the default ggplot2 theme with the specified ggthemr theme by using the `ggplot2::theme_set()` function.\n2. It modifies the aesthetic defaults for all geoms using the `ggplot2::update_geom_defaults()` function.\n3. It creates functions for all the different scales in the global environment.\n\nIn 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:\n```{r}\nggthemr_reset()\ndust_theme \u003c- ggthemr('dust', set_theme = FALSE)\nexample_plot\nexample_plot + dust_theme$theme\nexample_plot + dust_theme$theme + dust_theme$scales$scale_fill_discrete()\ndo.call(what = ggplot2::update_geom_defaults, args = dust_theme$geom_defaults$new$bar)\nggplot(diamonds, aes(price)) + geom_histogram(binwidth = 850) + dust_theme$theme\n```\n\n\nLicense\n-------\nReleased under GPL-3.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMikata-Project%2Fggthemr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMikata-Project%2Fggthemr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMikata-Project%2Fggthemr/lists"}