使用R和ggplot2进行连续刻度时出错

使用R和ggplot2进行连续刻度时出错,r,ggplot2,R,Ggplot2,我遵循《黑客机器学习》一书中的一个例子R2.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", pa

我遵循《黑客机器学习》一书中的一个例子<代码>R2.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)")
state.plot试试这个

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)")

state.plot新版的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)")

state.plot这本书似乎是在ggplot2的一个相当重要的版本发布之前出版的,该版本对软件包进行了相当大的修改。您可能想看看(具体地说,没有更多的
format
参数;您现在应该使用
labels
)所以更具体地说,我认为应该是
scale\u x\u date(breaks=“5年”,labels=date\u format(“%Y”)
(这是基于
?scale\u x\u date
中的示例)