I am having issue of ggplot in loop. It works well individually.
as below:
*plotgg<-
ggplot(renewalplot, aes(x = Month,y=Rate)) +
stat_summary(fun = mean, na.rm = TRUE,geom="bar")+
labs(x = "Month") +
ggtitle("Rate Change Distribution")+
theme(axis.text.x = element_text(angle = 90, hjust = 1))+
facet_grid(cols = vars(Year))
print(plotgg)*
when I put them in loop, it gives me error:
vars <- colnames(detailinfo_renewal_1)
varslist1 = vars[c(13)]
for (i in varslist1) {
renewalplot <- detailinfo_renewal_1 %>%
filter(Product=="FI")
plotgg<-
ggplot(renewalplot, aes(x = renewalplot[, i],y=Rate)) +
stat_summary(fun = mean, na.rm = TRUE,geom="bar")+
labs(x = i) +
ggtitle("Mean of Rate Change Distribution")+
theme(axis.text.x = element_text(angle = 90, hjust = 1))+
facet_grid(cols = vars(Year))
print(plotgg)
}
Much appreciated it! LC