如何创建一个新变量作为参考并以此为点着色?如果您不介意前 3 个方面的点也被着色,似乎可以工作。
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)

编辑:我已经设法让它从前 3 个方面删除颜色键,但不是不玩原始数据;
复制原始数据(因此每条记录有 2 个),然后使用冗余记录而不是使用边距图来生成“全部”方面。
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)

我不确定这是最好的方法,但也许有更多专业知识的人可以提供建议?