Add title name to list of ggplots from the names of dataframes in list

Viewed 1867

I am producing a list of boxplots from a list of data frames as so:

Bps<-lapply(dflist, function(x){
  gg<-ggplot(x, aes(x= x, y= y, fill= x))+
   geom_boxplot(position  = "dodge")+
    ggtitle(names(x))    
 })

The list of dataframes can be generated by:

 df1<-data.frame(x=seq(1:50), y=rep("Blank", "Non_blank",25))
 df2<-data.frame(x=seq(1:40), y=rep("Blank", "Non_blank",20))
 df3<-data.frame(x=seq(1:30), y=rep("Blank", "Non_blank",15))

dflist<-list(df1,df2,df3

I need to paste the names of the original dataframes as the title for each boxplot. So if dflist has 3 dataframes called dfA, dfB and dfC, these should be the titles of each boxplot made from the lapply function. I can only seem to get the name of a column and not the original dataframe name. Many thanks, M

1 Answers
Related