ggplot2 0.9.0自动从plot图例中删除未使用的因子级别?

我最近从版本0.8.9升级到ggplot2 0.9.0,现在我得到的是,我的情节的传说只显示在情节中使用的因素水平(它省略了未使用的)。 在它之前将所有的因素级别包括在图例中。 我正在运行Windows 7和R 2.15.0(今天之前的2.14.2)。

有没有其他人也find这个? 有没有一种方法可以让我的情节图例中显示未使用的因子水平?

library(ggplot2) df <- data.frame(fruit = rep(c("apple", "orange"), times=11), year = 1990:2011, qty = rnorm(22, 100, 20)) # This plot only gives "apple" in the legend now. # Before, I used to get both "apple" and "orange". qplot(year, qty, data = subset(df, fruit=="apple"), colour = fruit) 

qplot()用于在图例中给我“苹果”和“橙色”(即使只有“苹果”的点)。 现在我只在传说中得到“苹果”。

原因是这样 – 我制作了许多数据集的子集,我希望传说可以在各个地块之间进行标准化(通常我会欣赏未使用的级别会自动下降,而不必input水滴(),但是这是一个我想要那些未使用的水平)。 道歉,如果这只是我的电脑本地的问题。

是的,你想添加drop = FALSE到你的色阶:

 ggplot(subset(df,fruit == "apple"),aes(x = year,y = qty,colour = fruit)) + geom_point() + scale_colour_discrete(drop = FALSE) 

第二种方法是使用limits参数明确定义所需的条目:

 ggplot(subset(df,fruit == "apple"),aes(x = year,y = qty,colour = fruit)) + geom_point() + scale_colour_discrete(limits = c("apple", "orange"))