我有27个印度各州需要对水质进行测试和绘图。
state_1 <- subset(train,train$State.Name=="ANDHRA PRADESH")
ANDHRA <- as.data.frame(table(state_1$District.Name,state_1$Quality.Parameter,state_1$Year),stringsAsFactors = FALSE)
str(ANDHRA)
names(ANDHRA) <- c("District.Name","CHEMICAL","YEAR")
an <- ggplot(ANDHRA,aes(ANDHRA$CHEMICAL,ANDHRA$Freq,fill=ANDHRA$District.Name))
an+geom_bar(stat="identity",position = "dodge")+facet_grid(.~ANDHRA$YEAR)+
labs(title="TREND of Chemical Compostion in Andhra Pradesh Villages",x="Chemicals",y="Number Of Cases",fill="Districts in Andhra Pradesh")
所以我创建了一个用户定义的函数,它加载到全局环境中没有错误。
district_analysis<-function(a,b,d) {
b<- subset(train,train$State.Name=="a")
d<- as.data.frame(table(b$District.Name,b$Quality.Parameter,b$Year),stringsAsFactors = FALSE)
names(d) <- c("District.Name","CHEMICAL","YEAR")
an <- ggplot(d,aes(d$CHEMICAL,d$Freq,fill=d$District.Name))
an+geom_bar(stat="identity",position = "dodge")+facet_grid(.~d$YEAR)+labs(title=paste0("TREND of Chemical Compostion in ", a, " Villages"),x="Chemicals",y="Number Of Cases",fill=paste0("Districts in", a))
return(an) }
所以我用参数传递数据,但是我得到了这个错误。
> district_analysis(KERALA,bb,dd)
Error in labs(title = "TREND of Chemical Compostion in ", a, " Villages", :
object 'KERALA' not found
Called from: labs(title = "TREND of Chemical Compostion in ", a, " Villages",
x = "Chemicals", y = "Number Of Cases", fill = "Districts in",
a)
Browse[1]> n
可能是什么原因?
编辑
------现在的错误------
似乎它没有确定&#34; KERALA&#34;作为对象。
答案 0 :(得分:0)
错误很简单。您需要定义3个名称而不是4个(我不会在表格中看到CHEMICAL
/ Freq
,而您在错误的时间点上方创建一行)