[R] A question on grid - grid.points not spaced properly
Saptarshi Guha
sapsi at pobox.com
Tue Dec 5 23:33:49 CET 2006
Hi,
Thank you for the detailed explanation.
> If it's any consolation, this is true of the predefined plotting
> symbols
True. Its good to be aware of the structure of R graphics. Have been
planning to pick up the Grid book.
> p.s. An exercise for the reader: why do all of these plusses look
> the
> same on screen?
>
> plot(1:10, 1:10, pch="+")
Is this because we are getting the system/device font renderer(e.g
the postscript renderer, OS X font renderer)
to draw the character "+" so the widths/height will be exactly
measure, but R is drawing itself when doing pch=3 ?
Thanks
Saptarshi
Saptarshi Guha | sapsi at pobox.com | http://www.stat.purdue.edu/~sguha
On Dec 5, 2006, at 3:58 PM, Paul Murrell wrote:
> Hi
>
>
> Saptarshi Guha wrote:
>> Hi,
>> Thank you for the explanation. I have one further question -
>> should
>> i wish to plot to the screen, which units (apart from bigpts) for
>> exact
>> plotting.
>> Essentially i wish to create my own plotting character - hence the
>> pch="." and the surrounding dots - so it would be nice if i could
>> place
>> the surrounding dots exactly.
>
>
> R graphics is a vector system rather than a raster system, which means
> that all locations and dimensions are effectively on an infinite
> resolution device. There are no "pixels" to refer to. So you are
> already placing the dots exactly.
>
> When graphics are rendered by a specific device, there will be
> rounding
> if the device is raster (e.g., screen). So not all devices can render
> your dots exactly.
>
> If you know that your plotting character will only be rendered on a
> raster device, "native" coordinates in the top-level grid viewport
> refer
> (approximately) to pixels, e.g.,
>
>> grid.newpage()
>> grid.rect(x=0, y=0, width=10, height=10, default.units="native",
> just=c("left", "bottom"))
>> grid.rect(x=10, y=10, width=10, height=10, default.units="native",
> just=c("left", "bottom"))
>> grid.rect(x=20, y=20, width=10, height=10, default.units="native",
> just=c("left", "bottom"))
>
> but you can still get rounding problems and these coordinates are not
> available in any other grid viewport.
>
> In other words, you cannot predict exactly which pixels will get
> turned
> on when you draw something on screen with R graphics.
>
> If it's any consolation, this is true of the predefined plotting
> symbols
> too! (do all the plusses look the same on screen?)
>
> plot(1:10, 1:10, pch=3)
>
> Paul
>
> p.s. An exercise for the reader: why do all of these plusses look
> the
> same on screen?
>
> plot(1:10, 1:10, pch="+")
>
>
>> Thank you
>> Saptarshi Guha
>>
>>
>> Paul Murrell wrote:
>>> Hi
>>>
>>>
>>> Saptarshi Guha wrote:
>>>
>>>> Hello,
>>>> How can i 'fix' the following output.
>>>>
>>>> v=viewport(x=216/2, y=216/2,w=216, h=216,default.units = "bigpts")
>>>> pushViewport(v)
>>>> x=c(119,130,140,151)
>>>> y=c(124,124,124,124)
>>>> grid.points(x,y,size=unit
>>>> (1,"bigpts"),default.units="bigpts",pch=".")
>>>> grid.points(x-2,y,size=unit
>>>> (1,"bigpts"),default.units="bigpts",pch=".")
>>>> grid.points(x+2,y,size=unit
>>>> (1,"bigpts"),default.units="bigpts",pch=".")
>>>> grid.points(x,y-2,size=unit
>>>> (1,"bigpts"),default.units="bigpts",pch=".")
>>>> grid.points(x,y+2,size=unit
>>>> (1,"bigpts"),default.units="bigpts",pch=".")
>>>>
>>>>
>>>> One would expect to get a 4 figures composed of 5 dots each - 2
>>>> vertically spaced and 2 horizontally spaced symmetrically around
>>>> the
>>>> center dot.
>>>> However i seem to get odd results - e.g on Quartz(OS X) output,
>>>> the
>>>> last command, places the dot bang next to the center dot.
>>>> On 'jpeg' output with higest quality, this oddity happens with
>>>> the 'x
>>>> +2' command.
>>>>
>>>> This doesn't happen to all of the points, only some - and not
>>>> necc.
>>>> the edge figures.
>>>>
>>>> Is there anyway i can control this?
>>>>
>>>
>>> I think you are seeing a rasterization effect. Both on screen
>>> and in a
>>> bitmap format you are essentially turning on a single pixel at a
>>> time.
>>> The locations you are giving do not necessarily correspond to an
>>> exact
>>> pixel location (bigpoints are in 1/72 inches, but your screen
>>> might have
>>> a resolution of 96 ppi) so you just get the nearest pixel to that
>>> location. So the gap you specify of two bigpoints sometimes
>>> comes out
>>> as 2 pixels, sometimes as 1 pixel (for example).
>>>
>>> For comparison, try running your code on a PDF (or other vector
>>> format)
>>> device; the result is much more what you are expecting I think.
>>>
>>> Paul
>>>
>>>
>>>
>>>> Thanks
>>>> Saptarshi
>>>>
>>>> Saptarshi Guha | sapsi at pobox.com | http://www.stat.purdue.edu/
>>>> ~sguha
>>>>
>>>> ______________________________________________
>>>> R-help at stat.math.ethz.ch 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.
>>>>
>>>
>
> --
> Dr Paul Murrell
> Department of Statistics
> The University of Auckland
> Private Bag 92019
> Auckland
> New Zealand
> 64 9 3737599 x85392
> paul at stat.auckland.ac.nz
> http://www.stat.auckland.ac.nz/~paul/
More information about the R-help
mailing list