ggplot does not work if it is inside a for loop although it works outside of it [duplicate]

Solution 1:

When in a for loop, you have to explicitly print your resulting ggplot object :

for (i in 1:5) { 
    print(ggplot(df,aes(x,y))+geom_point()) 
}