[R] a question about the output of plot
Richard M. Heiberger
rmh at temple.edu
Tue Apr 15 18:42:03 CEST 2014
Please see R FAQ 7.22
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*
(http://CRAN.R-project.org/package=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 Tue, Apr 15, 2014 at 5:51 AM, meng <laomeng_3 at 163.com> wrote:
> Yes,it works !
> What's the reason for it?
>
>
> Many thanks!
>
>
>
>
>
>
> --
> QQ: 1733768559
>
>
>
>
>
> At 2014-04-15 14:36:41,"Jim Lemon" <jim at bitwrit.com.au> wrote:
>>On 04/15/2014 11:46 AM, meng wrote:
>>> Hi all:
>>> I met a question about the output of plot.
>>> I want to output 3 plots.
>>> Method1: by function histogram{lattice}
>>> Method2: by function hist{graphics}
>>>
>>>
>>> But method1 failed(the output is empty),and only method 2 works.
>>> I can't find out the reason,and many thanks for your help.
>>>
>>>
>>> #Method1---failed(the output is empty)
>>> library(lattice)
>>> for(i in 1:3)
>>> {
>>> x<-rnorm(10)
>>>
>>>
>>> jpeg(paste("e:\\hist_",i,".jpeg"))
>>> histogram(x)
>>> dev.off()
>>> }
>>>
>>>
>>>
>>>
>>> #Method 2---works
>>> for(i in 1:3)
>>> {
>>> x<-rnorm(10)
>>>
>>>
>>> jpeg(paste("e:\\hist_",i,".jpeg"))
>>> hist(x)
>>> dev.off()
>>> }
>>>
>>Hi meng,
>>Try:
>>
>>print(histogram(x))
>>
>>Jim
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
More information about the R-help
mailing list