#Density/Distribution plot
if (length(standard.names) == 1){
melon.data.standard.avg<- ddply(melon.data.standard, paste(colnames(melon.data)[fac.pos]), colwise(mean))
# droplevels to get rid of excess factor levels for plotting
melon.data.standard.avg<-droplevels(melon.data.standard.avg)
for (i in colstart:colend){
plot<-ggplot()+
geom_histogram(data=melon.data, aes_string(x= paste(colnames(melon.data)[i])))+
geom_vline(data=melon.data.standard.avg, aes_string(xintercept= paste(colnames(melon.data)[i])), colour= "lightblue3")+
theme_bw()+
geom_text(data=melon.data.standard.avg, aes_string(x=paste(colnames(melon.data)[i]), y= "0", label='paste(standard.names)') , angle=90, colour="lightblue3", hjust=0, vjust=0, size=3)
#save plot
ggsave(sprintf("Histogram.%s.%s.%s.png", (i-colstart+1), mol.type$mol.type[(i-colstart+1)], colnames(melon.data)[i]), width=6, height=6)
}
}
standard.names is used to ID standards and mark them on the distribution plot. If I make standard.names longer than 2 it works beautifully, but in a slightly different way. If there are no standards it works great, but I needed to account for only having one standard. When I run this code out of the function, it works. When I run the function with standard.names defined in the global space it works, but when I run it in the function it fails with the above error.
Does anyone have a clue what is going on because I am truly at a loss?
Brandon
Dennis,Yeah, I had everything in pieces and then put it together this last weekend. Each piece is fairly modular and I probably should have just cut out everything that wasn't necessary. Sorry about that.When I tried this:label = bquote(.(standard.names))I get a different error.Error in parse(text = x) :<text>:2:0: unexpected end of input1: 2421-1-M:99-B-2-B-^
When I tried this:
label = "substitute(standard.names)" #quotes because of aes_string()
Error: geom_text requires the following missing aesthetics: labelWhen I tried this:label = deparse(substitute(standard.names))It didn't cause an error, but the label ended up being plotted as "standard.names."Another possibility is that at the point where standard.names is accessed, the calling environment of the function is not 'visible' to the environment where standard.names is needed.I thought that too, but it's clearly using standard.names when it's determining if (length(standard.names) == 1){I sort of fixed it using the dataframe I already made. I'm not sure why I didn't use it before.
if (length(standard.names) == 1){
melon.data.standard.avg<- ddply(melon.data.standard, paste(colnames(melon.data)[fac.pos]), colwise(mean))
# droplevels to get rid of excess factor levels for plotting
melon.data.standard.avg<-droplevels(melon.data.standard.avg)
melon.data.standard.avg[fac.pos,1]<-standard.names
for (i in colstart:colend){
plot<-ggplot()+
geom_histogram(data=melon.data, aes_string(x= paste(colnames(melon.data)[i])))+
geom_vline(data=melon.data.standard.avg, aes_string(xintercept= paste(colnames(melon.data)[i]), colour= paste(colnames(melon.data)[fac.pos])))+
theme_bw() #+
#geom_text(data=melon.data.standard.avg, aes_string(x=paste(colnames(melon.data)[i]), y= "0", label = "deparse(standard.names)") , angle=90, colour="lightblue3", hjust=0, vjust=0, size=3)
#save plot
ggsave(sprintf("Histogram.%s.%s.%s.png", (i-colstart+1), mol.type$mol.type[(i-colstart+1)], colnames(melon.data)[i]), width=6, height=6)
}
} else {...
Works now, but I still don't understand what I was doing wrong.
Thanks for your efforts Dennis.
Brandon
On Mon, Jan 24, 2011 at 13:42, Dennis Murphy <djm...@gmail.com> wrote:label = bquote(.(standard.names))
Hadley
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/