尝试将它与 ggplot 一起使用时,格式默认函数出现错误

I am getting an Error in format default function when trying to use it with ggplot

这是我的代码:

yearly.ts<- data.frame (Years = as.Date(c('01/01/1985','01/01/1986','01/01/1987','01/01/1988','01/01/1989'),"%d/%m/%Y"),SUMS = c(sum(Appliance.df$Shipments[which(format(Appliance.df$Quarter, "%y")=="85")]),sum(Appliance.df$Shipments[which(format(Appliance.df$Quarter, "%y")=="86")]),sum(Appliance.df$Shipments[which(format(Appliance.df$Quarter, "%y")=="87")]),sum(Appliance.df$Shipments[which(format(Appliance.df$Quarter, "%y")=="88")]),sum(Appliance.df$Shipments[which(format(Appliance.df$Quarter, "%y")=="89")])))


ggplot(yearly.ts) + 
  geom_line(aes(Years,SUMS,color=SUMS)) + 
  labs(title = "LINE CHART",caption = "(based on data from yearly.ts)", x = "Years", y = "Shipments") + 
  ylim(16400,18500) + 
  scale_x_date(date_labels="%Y",date_breaks  ="1 years")

我得到的错误是:

Error in format.default(structure(as.character(x), names = names(x), dim = dim(x), : invalid 'trim' argument

我正在尝试复制如下所示的输出:

也许您需要将 Years 设置为因子:

yearly.ts$Years = as.factor(yearly.ts$Years)