2

我正在遵循书中的一个例子Machine Learning for HackersR 2.15.1并被ggplot 0.91使用。我收到以下错误:

Error in continuous_scale(aesthetics, "date", identity, breaks = breaks,  : 
unused argument(s) (major = "5 years", format = "%Y")
In addition: Warning message:
In discrete_scale(aesthetic, "manual", pal, ...) :
"legend" argument in scale_XXX is deprecated. Use guide="none" for suppress the guide   display.

我尝试运行的代码是

state.plot<-ggplot(all.sightings, aes(x=YearMonth,y=Sightings))+ 
    geom_line(aes(color="darkblue"))+ 
    facet_wrap(~State,nrow=10,ncol=5)+
    theme_bw()+ 
    scale_color_manual(values=c("darkblue"="darkblue"),legend=FALSE)+   
    scale_x_date(major="5 years", format="%Y")+ 
    xlab("Time")+ylab("Number of Sightings")+
    opts(title="Number of UFO sightings by Month-Year and U.S. State (1990-2010)")

我用过library(scales),但没有用。有任何想法吗?

4

2 回答 2

2

尝试这个

state.plot<-ggplot(all.sightings, aes(x=YearMonth,y=Sightings))+ 
    geom_line(aes(color="darkblue"))+ 
    facet_wrap(~State,nrow=10,ncol=5)+
    theme_bw()+ 
    scale_color_manual(values=c("darkblue"="darkblue"),guide=FALSE)+   
    scale_x_date(breaks = date_breaks("5 years"), labels = date_format("%Y"))+ 
    xlab("Time")+ylab("Number of Sightings")+
    opts(title="Number of UFO sightings by Month-Year and U.S. State (1990-2010)")
于 2012-08-30T09:21:40.197 回答
1

新版本的ggplot不再使用“ opts ”,所以我们需要将“ opts ”替换为“ labs ”。

正确的代码是:

state.plot<-ggplot(all.sightings, aes(x=YearMonth,y=Sightings))+ 
    geom_line(aes(color="darkblue"))+ 
    facet_wrap(~State,nrow=10,ncol=5)+
    theme_bw()+ 
    scale_color_manual(values=c("darkblue"="darkblue"),guide=FALSE)+   
    scale_x_date(breaks = date_breaks("5 years"), labels = date_format("%Y"))+ 
    xlab("Time")+ylab("Number of Sightings")+
    labs(title="Number of UFO sightings by Month-Year and U.S. State (1990-2010)")
于 2013-05-27T18:12:31.987 回答