Sorry it was a typo:
my code looks like:
plot_shad_CR<-function(x,y,agentid,CRagent,f){
library(ggplot2)
plotdata<-melt(f)
names(plotdata)<-c('x','y','z')
agent<-CRagent[[agentid]] # To make following expression shorter
ggplot((data.frame(x=CRX,y=CRY,sr=agent$sr)))+
geom_point(aes(x,y,colour=cut(sr,c(0,-10,-20,-30,-40,-50,-60,-70,-80))))+
geom_text(aes(x,y,color=cut(sr, c(0,-10,-20,-30,-40,-50,-60,-70,-80)),
label=round(sr,3)),vjust=1,legend=FALSE)+labs(colour="CRagents[[i]]$sr")+
geom_tile(aes(fill=z))
}
and I get as an error message this:
plot_shad_CR(CRX,CRY,1,CRagent,f)
Error in eval(expr, envir, enclos) : object 'z' not found
Calls: print ... lapply -> is.vector -> lapply -> FUN -> eval -> eval
________________________________
From: Dennis Murphy <[email protected]>
Cc: Rhelp <[email protected]>
Sent: Sat, November 20, 2010 4:24:15 PM
Subject: Re: [R] Merge two ggplots
Hi:
Perhaps a plus sign at the end of the line before geom_tile() would help.
Dennis
Hello everyone.
>I am using ggplot and I need some help to merge these two plots into one.
>
>plot_CR<-function(x,y,agentid,CRagent){
> library(ggplot2)
>
> agent<-CRagent[[agentid]] # To make following expression shorter
> ggplot((data.frame(x=CRX,y=CRY,sr=agent$sr)))+
> geom_point(aes(x,y,colour=cut(sr,c(0,-10,-20,-30,-40,-50,-60,-70,-80))))+
> geom_text(aes(x,y,color=cut(sr, c(0,-10,-20,-30,-40,-50,-60,-70,-80)),
>label=round(sr,3)),vjust=1,legend=FALSE)+labs(colour="CRagents[[i]]$sr")
>}
>
>
>plot_shad_f<-function(f){
> library(ggplot2)
>
> plotdata<-melt(f)
> names(plotdata)<-c('x','y','z')
> v<-ggplot(plotdata, aes(x, y, z = z))
> v + geom_tile(aes(fill=z))
>
>}
>
>The first plot puts points and texts below the points... in an area
>while the second function in the same are fills the background using
>geom_tiles... Is it possible somehow to merge these two plots into one?
>
>So far I have tried to merge the two functions as one but I fail as ggplot is
>not very clear to me what it needs.
>
>
> plotdata<-melt(f)
> names(plotdata)<-c('x','y','z')
>
> agent<-CRagent[[agentid]] # To make following expression shorter
> ggplot((data.frame(x=CRX,y=CRY,sr=agent$sr)))+
> geom_point(aes(x,y,colour=cut(sr,c(0,-10,-20,-30,-40,-50,-60,-70,-80))))+
> geom_text(aes(x,y,color=cut(sr, c(0,-10,-20,-30,-40,-50,-60,-70,-80)),
>label=round(sr,3)),vjust=1,legend=FALSE)+labs(colour="CRagents[[i]]$sr")
>
geom_tile(aes(fill=z))
>}
>
>Could you please help me?
>
>I would like to thank you in advance for your help
>
>Regards
>Alex
>
>
>
>
> [[alternative HTML version deleted]]
>
>
>______________________________________________
>[email protected] mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
>
>
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.