【发布时间】:2021-04-10 18:13:35
【问题描述】:
这是 (how to modify axis labels ggplot in R) 的延续。提供的代码效果很好。数据是手动创建的。所以我转移了一个更大的数据集,现在出现以下错误。
Error in aes(y = AnnualDifference, x = (reorder(Seriesttls, AnnualDifference))) + :
non-numeric argument to binary operator
这是正在使用的代码
jobgrowthbyindustry<-ggplot(data=nvces2, aes(y=AnnualDifference,x=
(reorder(Seriesttls,AnnualDifference)))+geom_col(color="blue")
+coord_flip()+labs(x=NULL)+ggtitle("Nevada Nonfarm Job Growth by Industry"))+
theme(plot.title.position = "plot",
plot.title = element_text(hjust =0.5))
如果有任何帮助,AnnualDifference 项目将使用以下代码创建
nvces<- nvces%>%
group_by(adjusted,areaname,seriescode)%>%
mutate(PreviousYear=lag(ravg,12),
PreviousMonth=lag(ravg),
AnnualDifference=ravg-PreviousYear,
MonthlyDifference=ravg-PreviousMonth,
MonthlyGrowthRate=MonthlyDifference/PreviousMonth,
PercentGrowthRate=AnnualDifference/PreviousYear)%>%
ungroup()
我的困惑是图表中涉及的项目的数据类型是相同的。 Seriesttls 是字符,AnnualDifference(或上一个问题中的 A)是数字。然而,在第一个我没有得到任何错误,而在第二个中,我做到了。有什么想法吗?
【问题讨论】:
-
head 可以提供一些数据来复制您的错误吗?我假设您检查了每一列的
class而没有假设它?
标签: r ggplot2 syntax-error numeric