I am trying to write a for loop that creates multiple plots, with the dots coloured based on columns in a dataframe:
variables <- colnames(df)[4:35]
for(x in variables){
Y<- df %>%
ggplot(aes(x = PC1, y = PC2,
colour = x)) +
geom_point() +
theme_bw(base_size=16) +
labs(x=paste0("PC1: ",round(var_explained[1]*100,1),"%"),
y=paste0("PC2: ",round(var_explained[2]*100,1),"%"))
gridExtra::grid.arrange(y)
}
this does not do as I like, at first it does not color the dots, and secondly does not return a grid with all plots.