Hi All,
I'm doing a bunch of plots by a factor using d_ply and would like to put the factor level name onto each plot. These are going to a file but currently they're untitled, making them hard to use. The simplified example below should have "A" the title of the first plot and "B" as the title of the second. The code below doesn't work and, with df as the function variable, I've tried:
labs( title = eval( parse(text = df) ) )
as well as every other combination I could think of. I'm not quite sure what d_ply is passing for the data frame name. Any ideas?
Thanks,
Bob
x <- 1:4
y <- 1:4
group <- factor( c("A","A","B","B") )
mydata <- data.frame(group, x, y)
mydata
my_ggplot <- function(df) {
ggplot(df, aes(x, y)) +
geom_line() +
labs(title = df ) # <---This is the line that doesn't work
}
# Test on whole data set
my_ggplot(mydata)
# Apply by group
pdf("plots_by_group.pdf")
d_ply(mydata, .(group), my_ggplot, .print = TRUE)
dev.off()