Dear Claudia,
I would like to thank you for your reply, according to 7.22 I have to put some print() statement inside my function. What I do not understand is where to put this line (at the beginning or at the end of the code?) I tried both but I get error message.

Moreover I would like to ask you if any inputs should be passed to the print(). I tried to pass inside the argument of ggplot but it didnt like it :(

Best Regards

7.22 Why do lattice/trellis graphics not work?

The most likely reason is that you forgot to tell R to display the
graph.  Lattice functions such as xyplot() create a graph object,
but do not display it (the same is true of ggplot2 graphics,
and Trellis graphics in S-Plus).  The print() method for the
graph object produces the actual display.  When you use these functions
interactively at the command line, the result is automatically printed,
but in source() or inside your own functions you will need an
explicit print() statement.



--- On Mon, 11/22/10, Claudia Beleites <cbeleites@units.it> wrote:

From: Claudia Beleites <cbeleites@units.it>
Subject: Re: [R] plot inside function does not work
To: r-help@r-project.org
Date: Monday, November 22, 2010, 1:34 PM

Alex, this may be FAQ 7.22

Claudia

On 11/22/2010 02:19 PM, Alaios wrote:
> Hello everyone,
> when I commit a plot using console(command line?) plot works fine. I have created a function that plots based on the input. This function is called plot_shad. When I call this function alone in the command line I get my plot.
>
> Then I tried to use another function as depicted_below to do some calculation before calling the function that does the plotting.
>
> plot_shad_map<-function(f,CRagent,agentid){
> � for (i in c(1:nrow(shad_map))){
> ��� for (j in c(1:ncol(shad_map))){
> ���� # Do something
> ��� }
> � }
> � plot_shad_f(shad_map) # This plots fine when used in command line. But inside this #function does not
> � return(shad_map)
> }
>
> Unfortunately I get no plot . What might be the problem?
>
> One more question how to get more plots at the same time. It seems that when I issue a new plot replaces the old plot.
>
> I would like to thank you in advance for you 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.


-- 
Claudia Beleites
Dipartimento dei Materiali e delle Risorse Naturali
Università degli Studi di Trieste
Via Alfonso Valerio 6/a
I-34127 Trieste

phone: +39 0 40 5 58-37 68
email: cbeleites@units.it

______________________________________________
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]]

