I'm trying to get a dataframe name to use it as title in ggplot
#create dataframes
N1 <- N2 <- N3 <- N4 <- data.frame(matrix(1:12, 3, 4))
#list dataframes
mylist = list(N1, N2, N3, N4)
#rename dataframes in list
names(mylist) = c("N1", "N2", "N3", "N4")
#plot each ggplot using one data frame
myggplots = lapply(mylist, function(x){
require(ggplot2)
a = ggplot(x, aes(x=X1, y = X2)) +
geom_point() +
ggtitle(paste0(x))
a
})
If I access myggplots[[1]] , the title is not the name of the dataframe (N1 in this case). However, each plot object is named correctly after the dataframe that was used to create it
I tried many codes, without success. It is important to create a list of ggplots!