Skip to content

Instantly share code, notes, and snippets.

@BrunoGrandePhD
Last active November 2, 2018 02:48
Show Gist options
  • Save BrunoGrandePhD/5b9e272720cce2798f870cc24541809d to your computer and use it in GitHub Desktop.
Save BrunoGrandePhD/5b9e272720cce2798f870cc24541809d to your computer and use it in GitHub Desktop.
How to dynamically make a plot symmetrical around 0 in ggplot2
library(ggplot2)

data <- data.frame(x = rnorm(1000, 1))

ggplot(data, aes(x)) + 
  geom_histogram(binwidth = 0.3, boundary = 0) + 
  geom_vline(xintercept = 0)

ggplot(data, aes(x)) + 
  geom_histogram(binwidth = 0.3, boundary = 0) + 
  geom_vline(xintercept = 0) +
  geom_blank(aes(x * -1))

Created on 2018-11-02 by the reprex package (v0.2.1)

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