Reputation: 1
I want to create similar radar plots from numerous country "data sets" and title each chart accordingly. Can someone help me get the loop right where R recognizes my dataframe? The error I get is:
> Error in is.data.frame(df) : object 'data_i' not found
Code:
data_China=rbind(rep(100,1) , rep(1,100) , data)
data_Indonesia=rbind(rep(100,1) , rep(1,100) , data)
data_India=rbind(rep(100,1) , rep(1,100) , data)
data_Kenya=rbind(rep(100,1) , rep(1,100) , data)
par(mfrow=c(2,2),mar=c(1, 1, 1, 1))
clist <- c("Indonesia", "China", "India", "Kenya")
for (i in clist) {
# Custom the radarChart !
radarchart(data_i , axistype=1 ,
#custom polygon
pcol=rgb(0.2,0.5,0.5,0.9) , pfcol=rgb(0.2,0.5,0.5,0.5) , plwd=4 ,
#custom the grid
cglcol="grey", cglty=1, axislabcol="black", caxislabels=seq(0,100,20), cglwd=0.8,
#custom labels
vlcex=0.6 , title="i"
)
}
Upvotes: 0
Views: 240
Reputation: 2170
You can place all the datasets into a list, and iterate over that:
dataList <- list(China = data_China,
Indonesia = data_Indonesia,
India = data_India,
Kenya = data_Kenya)
for (i in 1:length(dataList)) {
radarchart(dataList[[i]] , axistype=1 ,
#custom polygon
pcol=rgb(0.2,0.5,0.5,0.9) , pfcol=rgb(0.2,0.5,0.5,0.5) , plwd=4 ,
#custom the grid
cglcol="grey", cglty=1, axislabcol="black", caxislabels=seq(0,100,20), cglwd=0.8,
#custom labels
vlcex=0.6 , title=names(dataList)[i]
)
}
Upvotes: 1