I am trying to create 6 ggplot objects graphing the same graph but labeled differently, the labeling being stored in object{1:6}
ggrun<- c(1,2,3,4,5,6)
for(i in ggrun) {assign(paste0("ggplot_", i),
(ggplot(DF1, aes(x=X, y=Y, color=as.factor(get(paste0("object", i))[["cluster"]]))) + geom_point(fill = NA, size=1, alpha=0.6)))}
But this produced 6 identical objects, with the proper {1:6} names, but all with the same value of object6.
I checked my for loop too,
for(i in ggrun) {print(table(get(paste0("hdbscan_object", ggrun[i]))[["cluster"]]))}
and it spat out 6 distinct tables.
further, to make sure it was not my plotting command:
grid.arrange(grobs = g, ncol(3), nrow(2), top="Title of Graphs")
I manually assigned each item in the list object, e.g.:
g[[5]] = ggplot(DF1, aes(x=PC1, y=PC4, color=as.factor(get(paste0("object", "5"))[["cluster"]])))
+ geom_point(fill = NA, size=1, alpha=0.6)
and it ran correctly.
listof length i.e.g <- vector('list', length(ggrun))g <- vector('list', length(ggrun)), then I rang[[i]] = ggplot(DF1, aes(x=PC1, y=PC4, color=as.factor(get(paste0("object", ggrun[i]))[["cluster"]]))) + geom_point(fill = NA, size=1, alpha=0.6)and the same thing happened, only[[6]]contained information, corresponding toobject6object1[["cluster"]]andobject6[["cluster"]]Valuesobjects withtypeof()double andclass()numeric. Printing each of the contents, they are a series of numbers corresponding to the cluster identity1 1 1 1 1 2 2 4 4 4 4 4 4forloop in the second code block i.e.g <- vector('list', length(ggrun)); for(i in ggrun) g[[i]] <- ggplot(DF1, aes(x=PC1, y=PC4, color=as.factor(get(paste0("object", ggrun[i]))[["cluster"]]))) + geom_point(fill = NA, size=1, alpha=0.6)