Created
December 1, 2019 01:59
-
-
Save jeffreypullin/be752f11a136601ffecddc73ba0519b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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