Skip to content

Instantly share code, notes, and snippets.

@aurielfournier
Created March 11, 2021 23:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aurielfournier/a52265e4e7becea26073bb5704c27419 to your computer and use it in GitHub Desktop.
Save aurielfournier/a52265e4e7becea26073bb5704c27419 to your computer and use it in GitHub Desktop.
library(ggplot2)
dat1 <- data.frame(y=c(1,2,3,4,5),
x=c("a","b","c","d","f"))
dat2 <- data.frame(y=c(1,2,3,4,5),
x=c("b","c","d","e","f"))
plot1 <- ggplot(dat=dat1,
aes(x=x, y=y, color=x))+
geom_point()+
# this code below here is the same in both graphs
scale_color_manual(breaks=c("a","b","c","d","e","f"), # so this is all the bacteria groups, across all the graphs
values=c("red","orange",
"yellow","green",
"blue","purple")) # and this is their colors
plot2 <- ggplot(data=dat2,
aes(x=x, y=y, color=x))+
geom_point()+
scale_color_manual(breaks=c("a","b","c","d","e","f"),
values=c("red","orange",
"yellow","green",
"blue","purple"))
@aurielfournier
Copy link
Author

Rplot

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