I am creating a list of plots from a list of data frames and am trying to add a title to each plot corresponding to the name of the data frame in the list.
p<-ggplot(x,aes(x=Numbers,y=Signal)) + geom_point() + ggtitle(paste0(names(df.list)[x]))
Error in names(df.list)[x] : invalid subscript type 'list'
You can use
map2 from purrr to loop through the list and the names of the list simultaneously, creating a plot each time. In
.x refers to the first list and
.y refer to the second list, which you can use in your plotting code.
library(purrr) map2(dlist, names(dlist), ~ggplot(.x, aes(Numbers, Signal)) + geom_point() + ggtitle(.y))