Displaying 20 results from an estimated 8000 matches similar to: "strange interaction between rasterImage and Grid graphics"
2011 Feb 15
1
gList and gTree methods of grid::grobX
Dear all,
In an attempt to draw fill patterns in grid graphics, I have
encountered a behavior of grobX that I cannot understand from the
documentation. Consider this,
library(grid)
## gTree
g1 <- gTree(children=gList(
rectGrob(0.5,0.5, width=unit(0.8,"npc"),
height=unit(2,"cm")),
circleGrob(r=0.3)), vp=viewport(0.5,0.5))
##
2020 May 19
2
Graphic parameters with length zero in grid cause R to crash
Hi,
I found in grid package, if the graphic parameters have zero length, R crashes. In the
following code, I only tested `grid.rect()` and the `fill` parameter, but I think it should
be similar as other grid graphic functions.
In `gpar()` function, the graphic parameters are not allowed to have zero length, but
we can make them with zero length by first generating a `gpar` object and then
2010 Apr 17
2
grid.cap() requires more time?
Dear all,
I am puzzled by the following behavior of the new grid.cap() function,
which appears to run out of time when capturing the output of a
graphic. It works fine if I introduce a Sys.sleep(1) before executing
more code,
library(grid)
quartz()
grid.circle(gp=gpar(fill="black"))
gg <- grid.cap()
dev.new()
grid.raster(gg) ## completely blank
gg[gg!="white"] ## indeed
2009 Sep 19
1
matrix operations on grobs and grid units
Dear list,
As a minimal test of a more complex grid layout, I'm trying to find a
clean and efficient way to arrange text grobs in a rectangular layout.
The labels may be expressions, or text with a fontsize different of
the default, which means that the cell sizes should probably be
calculated using grobWidth() and grobHeight() as opposed to simpler
stringWidth() and stringHeight().
2010 Oct 01
1
colored rasterImage()
Hello,
I have been exploring the possibility to transition some code that
currently uses image() to use the new rasterImage(). To date, I
haven't been able to specify a color look-up strategy that works. For
example...
nx <- 100
ny <- 100
m <- matrix(data = rep(seq(0,1, length = nx), ny), ncol = nx, nrow =
ny, byrow = TRUE)
plot(1:nx, 1:ny, type = "n")
my.color
2009 Sep 28
2
dichromat, regexp, and grid objects
Dear list,
The dichromat package defines a dichromat function which "Collapses
red-green color distinctions to approximate the effect of the two
common forms of red-green colour blindness, protanopia and
deuteranopia."
library(dichromat)
library(grid)
colorStrip <-
function (colors = 1:3, draw = TRUE)
{
x <- seq(0, 1 - 1/length(colors), length = length(colors))
y <-
2006 Jul 29
3
placing rectangle behind plot
I am trying to create a lattice plot and would like to later, i.e. after
the plot is drawn, add a grey rectangle behind a portion of it.
The following works except that the rectrangle is on top of and
obscures a portion of the chart. I also tried adding col = "transparent"
to the gpar list but that did not help -- I am on windows and
perhaps the windows device does not support
2011 Nov 10
1
grid.pack and grid.frame bewilder me
Hello R friends,
I get quite confused in using the grid graphic function grid.pack( )
and grid.frame ( ). Here is a simple example:
library(grid)
grid.frame(name="frame1")
grid.pack("frame1",rectGrob(width=unit(0.5,"npc"),
height=unit(0.5,"npc"), gp=gpar(col="red")))
what I expect is a rectangle with half the default device's
2012 Oct 09
2
plot.new() and grid functions in multipage pdfs
Hi,
when using the grid package, I've come across this weird behaviour
where a call to plot.new() will start a new page for a multi-page pdf,
but then the margins will somehow behave strangely for all but the
first page: here is some code:
pdf("test.pdf"); plot.new(); grid.rect(gp = gpar(fill="blue"));
plot.new(); grid.rect(gp = gpar(fill="blue")); dev.off()
2008 Aug 17
1
Making use of names of viewports (grid)
The following code, though not brilliant, works on an A4 page. It
might look odd on other devices of a very different size.
=============X8------- cut here ----------------------------
require(grid)
wide <- 15
vps <- grid.layout(nrow = 3, ncol = 4,
widths = unit(rep(1, 4), rep("null", 4)),
heights = unit(c(99, 1, 99),
2011 Feb 15
1
Using rasterImage on a CairoWin device prevents adding further elements to device?
I was pointed to the Cairo package for plotting PNG images on a
device. I've been playing around with it, but found that after I use
the rasterImage function, I can't add anything any more to the device,
eg :
img <- readPNG(system.file("img", "Rlogo.png", package="png"))
r = as.raster(img[,,1:3])
r[img[,,4] == 0] = "white"
CairoWin()
2005 Dec 08
1
grid graphics gpar(fill) argument and jpeg device
Hi everybody,
I just notice a strange behaviour of gpar's fill argument when using
non-postscript devices:
The default of the argument is transparent (according to get.gpar("fill")).
So as expected, the following code draws a nice red rectangle in the
middle of my X11 or postscript device.
pushViewport(viewport(width=0.5, height=0.5))
grid.rect(gp=gpar(fill="red"))
2008 Aug 06
1
grid layout scaling viewport width based solely on height
Hello all,
I'm trying to write a function that produces a main plotting region
with several square plots along the right side. Ideally the size of
right side plots will scale only with the height of the entire plot,
yet never overlap with another secondary plot. The following two
snippets get close, however, as I resize the plot horizontally the
right side plots (green squares) get smaller
2011 Feb 09
2
using rasterImage within image
Has anyone yet tried incorporating rasterImage into the base image()
function? It seems to make a *huge* difference, with
a very small number of added/changed lines of code. (Of course I have
barely tested it at all.)
Is there any reason this *shouldn't* go into the next release?
> source("image.R")
> z <- matrix(runif(1e6),nrow=1000)
> image(z)
>
2008 Aug 08
2
gridBase and new.page() / grid.newpage()
Hello all,
I'm trying to write a function using the gridBase package. I'd like
to push several base subplots to a larger plot constructed with grid.
However, I'm having trouble getting consistent results when running
the function when the plotting window (quartz) is closed, when it is
left open and the plot function is repeated to the same window, and
when the output is saved to a
2010 Aug 04
1
gpar fill and transparency on devices
Dear list,
I'm puzzled by the graphical output in the following example,
library(grid)
foo <- function(){
grid.rect(gp=gpar(fill="black"))
print(get.gpar()$fill)
grid.rect(width=0.2,height=0.2)
}
png("test.png", bg = "transparent")
foo()
dev.off()
png("test1.png", bg = "white")
foo()
dev.off()
It seems that the default value of
2009 Dec 01
6
raster support in graphics devices
Hi
This is for developers of extension packages that provide extra
*graphics devices* for R.
In the *development* version of R, support has been added to the
graphics engine for sending raster images (bitmaps) to a graphics
device. This consists mainly of two new device functions: dev_Raster()
and dev_Cap().
The R_GE_version constant (in GraphicsEngine.h) has been bumped up to 6
as a
2010 Nov 17
1
rasterImage and coordinate conversion
Hi, I have a plot and I would like to overlay a PNG image over it. I'm
using the rasterImage function to do this, but the problem I'm facing
is working out the coordinates of the upper right corner of the final
image in user coordinates.
That is I can place the image so the lower left is located at the
bottom of the y-axis and the left end of the x-axis. Since my image is
say 100px x
2011 Apr 26
2
grid stringHeight
Dear all,
I'm puzzled by the behavior of stringHeight in the grid package.
Consider the following test,
library(grid)
test <- function(lab="dog", ...){
g1 <- textGrob(lab)
g2 <- rectGrob(height=grobHeight(g1), width=grobWidth(g1))
gg <- gTree(children=gList(g1,g2), ...)
print(c("height:", convertUnit(stringHeight(lab), "mm",
2010 Oct 20
1
need for speed on grid.rect
When I use grid.rect to print a multi-coloured grid, it is incredibly slow compared to a single colour grid, or even a two colour grid.
I've set out some simplified examples below. This is something I run literally thousands of times a day, so I would greatly appreciate any hints on how I might improve the speed???
library(grid)
pushViewport(viewport(
width = unit(100,