图形保存循环出错-必须为长度1(汇总值)

时间:2019-06-12 14:42:50

标签: r loops ggplot2 ggpubr

我正在尝试创建和保存各个组织的图形。我不断收到错误消息,指出“ summarise_impl(.data,点)中的错误:   Improved列的长度必须为1(汇总值),而不是0“

当我将所有组织合并在一起时,这些图表就会起作用,所以我不确定这里发生了什么!

从此数据开始:

library(ggpubr)
structure(list(Organization = c("A", "B", "C", "D", "E", "F", 
"G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S"
), imp_imp20_Improved = c(55.6, 100, 50, 0, 57.1, 0, 0, 45, 50, 
60, 100, 50, 66.7, 66.7, 33.3, 0, 50, 0, 50)), row.names = c(NA, 
-19L), class = c("tbl_df", "tbl", "data.frame"))

org<- c("A", "B", "C", "D", "E", "F", 
"G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S"
)

这是我的图形循环代码:

for(i in org) {
tiff(paste0("//graphs/",i,"_graph11.tiff"), units="in", width=3.5, height=3, res=300)

indicator_graph1<- indicators_ong %>% 
  filter(Organization==i) %>%
  summarise(Improved = imp_imp20_Improved,
            "Not Improved" = 100-imp_imp20_Improved)%>%
  gather(key="group") %>%
   arrange(desc(group))


labs <- paste0(indicator_graph1$group, "\n (", indicator_graph1$value,"%)")

z <- ggpie(indicator_graph1,"value",label=labs, fill= "group", color = "black", palette = c("darkgoldenrod1","azure3"), lab.pos = "in", lab.font = c(3,"black"),title="Improve 20")+ 
  theme(legend.position ="none")+
  font("title", size=10, hjust=0.5)

        print(z) 

dev.off()  
}

0 个答案:

没有答案