{"id":13858301,"url":"https://github.com/briandconnelly/ggplot2bdc","last_synced_at":"2026-03-15T05:43:32.374Z","repository":{"id":16325006,"uuid":"19074228","full_name":"briandconnelly/ggplot2bdc","owner":"briandconnelly","description":"Collection of themes and tools for modifying ggplot2 plots","archived":false,"fork":false,"pushed_at":"2017-03-16T20:54:11.000Z","size":8045,"stargazers_count":56,"open_issues_count":2,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-13T23:39:10.147Z","etag":null,"topics":["ggplot2","plot","r","theme"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/briandconnelly.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-23T15:10:19.000Z","updated_at":"2025-07-09T15:23:51.000Z","dependencies_parsed_at":"2022-09-07T11:52:20.965Z","dependency_job_id":null,"html_url":"https://github.com/briandconnelly/ggplot2bdc","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/briandconnelly/ggplot2bdc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/briandconnelly%2Fggplot2bdc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/briandconnelly%2Fggplot2bdc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/briandconnelly%2Fggplot2bdc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/briandconnelly%2Fggplot2bdc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/briandconnelly","download_url":"https://codeload.github.com/briandconnelly/ggplot2bdc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/briandconnelly%2Fggplot2bdc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281642036,"owners_count":26536358,"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","status":"online","status_checked_at":"2025-10-29T02:00:06.901Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["ggplot2","plot","r","theme"],"created_at":"2024-08-05T03:02:03.418Z","updated_at":"2025-10-29T14:56:21.482Z","avatar_url":"https://github.com/briandconnelly.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\ntitle: ggplot2bdc README\nauthor: Brian Connelly\noutput: md_document\n---\n\n```{r global_options, echo=FALSE}\nknitr::opts_chunk$set(fig.path=\"figure/\", warning=FALSE, message=FALSE,\n                      error=FALSE)\n```\n\n# ggplot2bdc\n\nggplot2bdc is a collection of themes and other things that can be used when creating plots with [ggplot2](http://ggplot2.org/).\nFor those using the [development version of ggplot](https://github.com/hadley/ggplot2), subtitles and captions are supported.\n\n- Themes\n    - `theme_bdc_grey`\n    - `theme_bdc_paneled`\n    - `theme_bdc_microtiter`\n    - `theme_bdc_lattice_population`\n- Modifying Plots\n    - Removing Plot Elements\n        - `gg_remove_titles`, `gg_remove_title`, `gg_remove_subtitle`, `gg_remove_caption`, `gg_remove_title.x`, `gg_remove_title.y`\n        - `gg_remove_ticks`, `gg_remove_ticks_x`, `gg_remove_ticks_y`\n        - `gg_remove_grid`, `gg_remove_grid_major`, `gg_remove_grid_minor`, `gg_remove_grid_x`, `gg_remove_grid_y`\n        - `gg_remove_legend`, `gg_remove_legend_title`, `gg_remove_legend_key`, `gg_remove_legend_text`, `gg_remove_legend_background`\n        - `gg_remove_background`, `gg_remove_background_canvas`, `gg_remove_background_legend`, `gg_remove_background_facet`\n    - Rescaling\n        - `gg_rescale`\n        - `gg_rescale_golden`\n        - `gg_rescale_square`\n- Modifying Files Containing Plots\n    - `trim_whitespace`\n- Misc\n    - `ggsave_golden`\n    - `span`\n\n\n## Installation\n\n`ggplot2bdc` is not on [CRAN](http://cran.r-project.org/), but you can use [devtools](http://cran.r-project.org/web/packages/devtools/index.html) to install the latest and greatest version.\nTo do so:\n\n```{r Installation, eval=FALSE}\nif(!require(\"devtools\")) install.packages(\"devtools\")\ndevtools::install_github(\"briandconnelly/ggplot2bdc\")\n```\n\n## Examples\n\nTo gain access to the following themes, etc. provided, first load the `gplot2bdc` package.\nWe'll also load `ggplot`, `dplyr`, and `magrittr` for these examples.\n\n```{r}\nlibrary(ggplot2bdc)\nlibrary(ggplot2)\nlibrary(dplyr)\nlibrary(magrittr)\n```\n\n### Themes\n\n#### theme_bdc_grey\n\n`theme_bdc_grey` is a clean theme that uses thin grey panels on a white background.\nLegends are placed above.\nFacet labels are displayed as black text on a grey background.\n\n```{r theme_bdc_grey}\npUnemploy \u003c- ggplot(data = economics, aes(x = date, y = unemploy)) +\n    geom_line() +\n    scale_x_date() +\n    labs(x = \"Year\", y = \"Thousands of Persons\",\n         title = \"Monthly Unemployment\", subtitle = \"Seasonally Adjusted\",\n         caption = \"Source: Federal Reserve Bank of St. Louis\") +\n    theme_bdc_grey()\npUnemploy\n```\n\nSubtle grid lines can be added to the panels with the `grid.x` and `grid.y` parameters.\nThese also affect minor grid lines, which can further be controlled with the `gridmin.x` and `gridmin.y` parameters.\n\n```{r theme_bdc_grey_grid}\nmidwest$inmetro \u003c- factor(midwest$inmetro, levels = c(0, 1),\n                          labels = c(\"Rural\", \"Metro\"))\n\nggplot(data = midwest,\n       aes(x = inmetro, y = percbelowpoverty, color = state, shape = state)) +\n    stat_summary(fun.y = \"mean\", geom = \"line\", aes(group = state)) +\n    stat_summary(fun.y = \"mean\", geom = \"point\") +\n    scale_color_hue(name = \"State\") +\n    scale_shape_discrete(name = \"State\") +\n    labs(x = NULL, y = \"Percent\",\n         title = \"Poverty in the Midwest\",\n         subtitle = \"Poverty rates in rural and metro communities\") +\n    coord_equal(ratio = 0.5) +\n    theme_bdc_grey(ticks.x = FALSE, grid.y = TRUE)\n```\n\nSome people prefer to display categorical data without tick marks along the axis.\nThese are included by default, but can be removed by setting either the `ticks.x` or `ticks.y` parameters to `FALSE`.\n\nWe can also use facets to divide the data by state:\n\n```{r theme_bdc_grey-facets1}\nggplot(data = midwest, aes(x = inmetro, y = percbelowpoverty)) +\n    facet_grid(. ~ state) +\n    stat_summary(fun.y = \"mean\", geom = \"line\", aes(group = state)) +\n    stat_summary(fun.y = \"mean\", geom = \"point\") +\n    labs(x = NULL, y = \"Percent\",\n         title = \"Poverty in the Midwest\",\n         subtitle = \"Poverty rates in rural and metro communities\") +\n    coord_equal(ratio = 0.5) +\n    theme_bdc_grey(grid.y = TRUE)\n```\n\n\n```{r theme_bdc_grey-facets2}\ntxcities \u003c- txhousing %\u003e%\n    filter(city %in% c(\"Austin\", \"Dallas\", \"El Paso\", \"Fort Worth\", \"Houston\",\n                       \"San Antonio\"))\n\npTX \u003c- ggplot(data = txcities, aes(x = year, y = median / 1000)) +\n    facet_grid(city ~ .) +\n    stat_summary(fun.data = \"mean_cl_boot\", geom = \"ribbon\",\n                 color = NA, alpha = 0.3) +\n    stat_summary(fun.y = \"mean\", geom = \"line\") +\n    labs(x = \"Year\", y = \"Thousands of Dollars\",\n         title = \"Home Prices are Getting Bigger in Texas\",\n         subtitle = \"Median Home Prices in Texas' Largest Cities\",\n         caption = \"Source: TAMU Real Estate Center\")\n\npTX + theme_bdc_grey()\n```\n\n\n#### theme_bdc_paneled\n\n`theme_bdc_paneled` is a clean theme that displays plots without borders on grey panels.\nLegends are placed above.\nFacet labels are displayed as plan black text.\nSubtle grid lines can be added to the panels with the `grid.x` and `grid.y` parameters, and tick marks can be managed with `ticks.x` and `ticks.y`.\nBy default, grid lines are used along the Y axis.\nThis theme is best suited for plots with multiple facets.\n\n```{r theme_bdc_paneled}\npTX + theme_bdc_paneled()\n```\n\n\n#### theme_bdc_microtiter\n\n`theme_bdc_microtiter` is a specialized theme for use in creating figures that represent 96-well microtiter plates.\n\n```{r loadplatemap,echo=FALSE}\nlibrary(dplyr)\nplatemap \u003c- read.csv(\"~/Dropbox/Research/Documents/Blog/Blog Post-Analyzing Bacterial Growth/data/platemap.csv\") %\u003e%\n    mutate(Row = as.numeric(match(toupper(substr(Well,1,1)), LETTERS)), Column = as.numeric(substr(Well,2,5)))\nplatemap$Environment \u003c- as.factor(platemap$Environment)\n```\n\n```{r theme_bdc_microtiter}\npPlate \u003c- ggplot(data = platemap, aes(x = Column, y = Row)) +\n    geom_point(data = expand.grid(Column = seq(1,12), Row = seq(1,8)),\n               color = \"grey90\", fill = \"white\", shape = 21, size = 8) +\n    geom_point(aes(shape = Environment, color = Strain), size = 9) +\n    coord_fixed(ratio = (13/12)/(9/8), xlim = c(0.5, 12.5), ylim = c(0.6, 8.4)) +\n    scale_y_reverse(breaks = seq(1, 8), labels = LETTERS[1:8]) +\n    scale_x_continuous(breaks = seq(1, 12), position = \"top\") +\n    labs(title = \"Plate Layout for My Experiment\", subtitle = \"25 March 2016\") +\n    guides(shape = guide_legend(override.aes = list(size = 3)),\n           color = guide_legend(override.aes = list(size = 3))) +\n    theme_bdc_microtiter()\n\npPlate\n```\n\n\nFor more information, see the [Plotting Microtiter Plate Maps](http://bconnelly.net/2014/05/plotting-microtiter-plate-maps/).\n\n#### theme_bdc_lattice_population\n\n`theme_bdc_lattice_population` is a specialized theme intended to display populations of individuals structured spatially in a lattice.\n\n```{r theme_bdc_lattice_population}\nggplot(data = filter(rockpaperscissors, Time == 10),\n       aes(x = X, y = Y, color = Type)) +\n        geom_point(shape=15) +\n        coord_equal(ratio=1) +\n        scale_color_hue() +\n        theme_bdc_lattice_population()\n```\n\nWe can also show multiple population states:\n\n```{r theme_bdc_lattice_population-facets}\nggplot(data = filter(rockpaperscissors, Time %in% c(0, 200, 400, 600)),\n       aes(x = X, y = Y, color = Type)) +\n    facet_wrap(~Time, nrow = 1, ncol = 4) +\n    geom_point(shape = 15) +\n    coord_equal(ratio = 1) +\n    scale_color_hue(guide = FALSE) +\n    labs(title = \"Rock, Paper, Scissors\",\n         subtitle = \"Wait, is it ON three or AFTER three?\",\n         caption = \"Data from simulation on a 50x50 lattice\") +\n    theme_bdc_lattice_population()\n```\n\n\nThis is also a great opportunity to create an animation.\nWe can use [gganimate](https://github.com/dgrtwo/gganimate) to create an animated GIF showing the population for the first 10 time steps.\n\n```{r lattice-animation, eval=FALSE}\nlibrary(gganimate)\n\np \u003c- ggplot(data = filter(rockpaperscissors, Time \u003c 10),\n       aes(x = X, y = Y, color = Type, frame = Time)) +\n    geom_point(shape = 15, size = 3) +\n    coord_equal(ratio = 1) +\n    scale_color_hue(guide = FALSE) +\n    labs(title = \"Rock, Paper, Scissors at t=\") +\n    theme_bdc_lattice_population()\n\ngg_animate(p = p, saver = \"gif\", interval = 0.2)\n```\n\n```{r lattice-animation-save, echo=FALSE}\nlibrary(gganimate)\n\np \u003c- ggplot(data = filter(rockpaperscissors, Time \u003c 10),\n       aes(x = X, y = Y, color = Type, frame = Time)) +\n    geom_point(shape = 15, size = 3) +\n    coord_equal(ratio = 1) +\n    scale_color_hue(guide = FALSE) +\n    labs(title = \"Rock, Paper, Scissors at t=\") +\n    theme_bdc_lattice_population()\ngg_animate(p = p, filename = \"figure/lattice-anim.gif\", interval = 0.2)\n```\n\n![](figure/lattice-anim.gif)\n\n\n### Modifying Plots\n\nAlthough you can always change a plot's properties using ggplot2's `theme` function, it's often difficult to remember which elements control a plot's visual characteristics.\nThese and other `gg_` functions make it a bit easier to quickly alter a plot.\n\n\n#### gg_rescale_golden\n\n`gg_rescale_golden` adjusts the proportions of the axes of the given plot object so that follow the golden ratio (horizontally).\nIf no plot is provided, the last plot that was displayed is used.\n\n```{r gg_rescale_golden}\nggplot(mtcars, aes(x = hp, y = mpg)) +\n    geom_smooth(method = \"loess\") +\n    geom_point(shape = 1) +\n    labs(x = \"Horsepower\", y = \"Fuel Efficiency (mpg)\") +\n    theme_bdc_grey()\n```\n\n```{r gg_rescale_golden2}\ngg_rescale_golden()\n```\n\n\n#### gg_rescale_square\n\n`gg_rescale_square` adjusts the proportions of the axes of the given plot object so that they are equal.\nIf no plot is provided, the last plot that was displayed is used.\n\n```{r gg_rescale_square}\nggplot(data = economics, aes(x = date, y = unemploy)) +\n    geom_line() +\n    labs(x = \"Date\", y = \"Thousands of Unemployed Persons\") +\n    theme_bdc_grey()\n```\n\n```{r gg_rescale_square2}\ngg_rescale_square()\n```\n\n\n#### gg_rescale\n\n`gg_rescale` adjusts the proportions of the axes of the given plot object to the given ratio.\nIf no plot is provided, the last plot that was displayed is used.\n\n```{r gg_rescale}\nggplot(data = economics, aes(x = date, y = unemploy)) +\n    geom_line() +\n    labs(x = \"Date\", y = \"Unemployed Persons (x1000)\") +\n    theme_bdc_grey()\ngg_rescale(ratio = 16 / 9)\n```\n\n\n#### ggsave_golden\n\n`ggsave_golden` saves the given plot to the given filename.\nThe dimensions of the resulting image file's canvas will follow the golden ratio, which is useful in conjunction with `gg_rescale_golden`.\nIf no plot is specified, the most recently displayed plot is used.\n\n```{r ggsave_golden,eval=FALSE}\n# Save our plot of unemployment from earlier\nggsave_golden(filename = \"monthly_unemployment.pdf\", plot = pUnemploy)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbriandconnelly%2Fggplot2bdc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbriandconnelly%2Fggplot2bdc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbriandconnelly%2Fggplot2bdc/lists"}