How to create a new variable as a reference and color its points? It seems to work if you don't mind the dots in the first three faces being colored.
mtcars$ref <- as.factor(mtcars$gear) p <- ggplot(mtcars, aes(mpg, wt)) + geom_point(aes(col=as.factor(gear))) p + facet_grid(.~ref, margins = TRUE)

EDIT: I managed to get him to remove the color key from the first three faces, but not without the source data;
Duplicate the source data (therefore, there are two records for each record), and instead use the field graph to create an βallβ facet, using backup records instead.
library(ggplot2) mtcars$ref <- (mtcars$gear) # create the duplicate dat <- do.call("rbind", replicate(2, mtcars, simplify = FALSE)) # give the duplicates a false value for "gear" so they can be plotted together #This value can then be used for faceting, grouping everything with "all". dat$ref[1:32] <- "all" # where not in the "all" facet, change "gear" to one (so they are plotted with the same colour) dat$gear[dat$ref != "all"] <- 1 # then plot using ref as the facet and gear to colour points. p <- ggplot(dat, aes(mpg, wt)) + geom_point(aes(col=as.factor(gear))) p + facet_grid(.~ref, margins = F)

I'm not sure the best way to do this, but maybe someone with more experience can advise?
Adam kimberley
source share