0

I couldn't print ggplots in for loops. I tried with or without print() function, but both didn’t work. I'd love to see the plots in the plot panels. I do not want to save images like png, tiff or others. I also wonder how to see all the plots in the plot panel at once not one by one.

for(index in org_kmmse$question_num %>% unique()){
  org_kmmse %>% filter(question_num==index) %>%
    print(ggplot()+geom_bar(data =., aes(x = answer,fill = diag_nm))+
    labs(title = index))
  Sys.sleep(2)
}

and I get below error message

Error in max(x) : invalid 'type' (list) of argument`

Where should I change unlist function in the for loop? P.S. org_kmmse dimension is 480 by 9

learner
  • 1
  • 1
  • Try chaining the print statement to the end (after the ggplot call) with `%>% print()` – Dave2e Nov 25 '22 at 04:46
  • 1
    @Dave2e I try it but it still does not work....additionally ```for(index in org_kmmse$question_num %>% unique()){ p <- org_kmmse %>% filter(question_num==index) %>% ggplot()+geom_bar(aes(x = answer,fill = diag_nm))+ labs(title = index) print(p) }``` didn't work – learner Nov 25 '22 at 06:54

0 Answers0