由于问题涉及this post,我将解决方案添加到那里给出的代码中:
# get Petal.Length for each species separately
df1 <- subset(iris, Species == "virginica", select=c(Petal.Length, Species))
df2 <- subset(iris, Species == "versicolor", select=c(Petal.Length, Species))
df3 <- subset(iris, Species == "setosa", select=c(Petal.Length, Species))
# construct species 1 vs 2, 2 vs 3 and 3 vs 1 data
df <- data.frame(x=c(df1$Petal.Length, df2$Petal.Length, df3$Petal.Length),
y = c(df2$Petal.Length, df3$Petal.Length, df1$Petal.Length),
grp = rep(c("virginica.versicolor", "versicolor.setosa", "setosa.virginica"), each=50))
df$grp <- factor(df$grp)
# plot
require(ggplot2)
ggplot(data = df, aes(x = x, y = y)) + geom_point(aes(colour=grp)) + facet_wrap( ~ grp) +
labs(colour="The Groups")
导致下图:
我添加的用于设置图例标题的部分是+labs(colour="The Groups")。 labs 也可用于将标题设置为其他美学:
+ labs(x="x-axis title", y="y-axis title", fill="fill legend title", shape="shape legend title", colour="colour legend title")
也许还有我忘记的其他人。
最后一句话:您要求更改“分面分组变量标签”的名称。这实际上不是您想要做的以及我的解决方案所做的。它更改了用于着色的变量的标签 (aes(colour=grp))。碰巧这个相同的变量也用于分面 (facet_wrap( ~ grp))。