Skip to content

Instantly share code, notes, and snippets.

@andrewheiss
Created July 27, 2018 17:34
Show Gist options
  • Save andrewheiss/71a0f17a7ceeccf16c8450789dff2a4d to your computer and use it in GitHub Desktop.
Save andrewheiss/71a0f17a7ceeccf16c8450789dff2a4d to your computer and use it in GitHub Desktop.
library(tidyverse)
library(patchwork)

make_plot <- function(cut) {
  ggplot(data = filter(diamonds, cut == cut, color %in% LETTERS[4:5]),
         aes(x = carat, y = price)) +
    geom_point() +
    facet_wrap(~ color) +
    labs(title = cut)
}

make_plot("Fair") + make_plot("Good")

@andrewheiss
Copy link
Author

library(tidyverse)
library(patchwork)

make_plot <- function(cut, omit_y = FALSE) {
  p <- ggplot(data = filter(diamonds, cut == cut, color %in% LETTERS[4:5]),
              aes(x = carat, y = price)) +
    geom_point() +
    facet_wrap(~ color) +
    labs(title = cut)
  
  if (omit_y) {
    p + theme(axis.title.y = element_blank(),
              axis.ticks.y = element_blank(),
              axis.text.y = element_blank())
  } else {
    p
  }
  
}

make_plot("Fair") + make_plot("Good", omit_y = TRUE)

Created on 2018-07-27 by the reprex package (v0.2.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment