I’m creating a list of plots (by ggplot2) using lapply
let’s say I have this function
plot <- function(x){
ggplot(x,aes(x=timepoints,means)) +
geom_point() +
geom_line() +
scale_x_continuous(name='some name') +
scale_y_continuous(name='another name') +
geom_errorbar(aes(ymin=means-stderrs,ymax=means+stderrs),width=2) +
opts(title = names(x))
}
I’m going to loop this through a list of data frames, here is an example of two data frames within the list:
$name1
means stderrs timepoints
1 603.784863 289.952382 0
2 120.00 99.000 20
$name2
means stderrs
1 17.425819 5.204339 0
2 25.9 8.0 20
My problem:
the names(x) part of my ggplot function will name each plot ‘means’ as opposed to the actual name of that data frame (e.g. name1,name2)
the function is in list[[i]] and I want the the name of that actual data frame, which would be names(list[i]).
question:
is there a way to refer to an outer layer in the list, so to speak? or is there an easier way to get a list of these plots w/ their respective names?
It’s not pretty but it works.