Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.