Skip to content

Instantly share code, notes, and snippets.

@jeffreypullin
Created December 1, 2019 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffreypullin/be752f11a136601ffecddc73ba0519b9 to your computer and use it in GitHub Desktop.
Save jeffreypullin/be752f11a136601ffecddc73ba0519b9 to your computer and use it in GitHub Desktop.
library(ggplot2)
set.seed(42)
x <- 1:20
y1 <- 2 * x + 3
y2 <- rep(y1,2) + rnorm(40,0,4)
y3 <- rep(y1,2) + rnorm(40,0,10)
y <- c(y2, y3)
type <- factor(rep(c("clyde","irving"), each = 40))
facet <- factor(rep(c("a","b"), each = 20))
df <- data.frame(x = rep(x, 4), y, colour, facet)
ggplot(df, aes(x, y, col = type, shape = type)) +
geom_point() +
# Specifying the same legend title merges the legends. From:
# https://stackoverflow.com/a/49791164
labs(x = "x", y = "y", col = "What I want", shape = "What I want") +
geom_abline(intercept = 3, slope = 2) +
facet_wrap(vars(facet)) +
scale_colour_manual(values = c("blue","red")) +
scale_shape_manual(values = c(20, 3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment