Hi:
On Sun, Nov 21, 2010 at 5:55 AM, Alaios <alaios@yahoo.com> wrote:
> 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)))+
>
^^^^^^^^^^^^^^ where do these come
from?
> 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))
> }
>
It's a *much* saner approach to arrange the data before submitting it to
ggplot(). In other words, generate a data frame with the the variables CRX,
CRY sr and/or its corresponding cuts and *then* submit it to ggplot(). The
hard work is to produce a data frame that will run simply through ggplot().
HTH,
Dennis
>
> 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 <djmuser@gmail.com>
> *To:* Alaios <alaios@yahoo.com>
> *Cc:* Rhelp <r-help@r-project.org>
> *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
>
> On Sat, Nov 20, 2010 at 6:30 AM, Alaios <alaios@yahoo.com> wrote:
>
>> 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]]
>>
>>
>> ______________________________________________
>> R-help@r-project.org 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]]