[R] Plot to a device and examine the plot?

Shu Fai Cheung @hu|@|@cheung @end|ng |rom gm@||@com
Mon Oct 16 04:31:51 CEST 2023


Thanks for the suggestion. I believe it is exactly what I need. I will
try this function. Thanks!

Regards,
Shu Fai

On Mon, Oct 16, 2023 at 3:39 AM Paul Murrell <paul using stat.auckland.ac.nz> wrote:
>
> Hi
>
> You could also look at dev.capture(), depending on which screen device
> you are using.
>
> Paul
>
> On 16/10/23 05:24, Duncan Murdoch wrote:
> > On 15/10/2023 12:05 p.m., Shu Fai Cheung wrote:
> >  > Let me clarify my question:
> >  >
> >  > plot.new()
> >  > polygon(c(.5, .5, .75, .8), c(.25, .3, .4, .5))
> >  >
> >  > If the device is an on-screen device, can I check whether a
> > particular area
> >  > has anything drawn on it, or, to be precise, whether the color of a
> >  > particular area has all pixels equal to the background color. That is, if
> >  > the background is white, can I know whether a particular area is white?
> >  >
> >  > E.g., in the case above, the area bounded by rect(0, 0, .25, .25) is
> >  > completely white, while the area bounded by rect(0, 0, .75, .75) is not
> >  > because part of border of the polygon, black by default, has been
> > drawn in
> >  > this area.
> >  >
> >  > If the device is an image file, then I can check the color of a pixel. I
> >  > would like to know whether I can do the same with an on-screen device.
> >  >
> >
> > I think the answer is that you can't do that in general. However, in
> > general you can copy a plot to a different device using dev.copy() and
> > examine it there. It won't be pixel-by-pixel identical, but will
> > contain the same components, likely with slightly different scaling and
> > positioning if the new device isn't the same as the old one.
> >
> > You can also save the commands that drew the plot using recordPlot() and
> > redraw it using replayPlot() (which is essentially what dev.copy()
> > does), but the format of the object saved by recordPlot() is not
> > documented, and is subject to change with R version changes.
> >
> > Duncan Murdoch
> >
> > ______________________________________________
> > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > <https://stat.ethz.ch/mailman/listinfo/r-help>
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > <http://www.R-project.org/posting-guide.html>
> > and provide commented, minimal, self-contained, reproducible code.
>
> --
> Dr Paul Murrell
> Te Kura Tatauranga | Department of Statistics
> Waipapa Taumata Rau | The University of Auckland
> Private Bag 92019, Auckland 1142, New Zealand
> 64 9 3737599 x85392
> paul using stat.auckland.ac.nz
> www.stat.auckland.ac.nz/~paul/
>



More information about the R-help mailing list