我想从众多国家"数据集"创建类似的雷达图。并相应地标出每个图表。有人可以帮我在R识别我的数据帧的地方找到循环吗?我得到的错误是:
> is.data.frame(df)中的错误:object' data_i'找不到
代码:
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"
)
}
答案 0 :(得分:0)
您可以将所有数据集放入一个列表中,然后对其进行迭代:
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]
)
}