Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty raster #943

Closed
ben519 opened this issue Apr 14, 2014 · 3 comments · Fixed by #1077
Closed

Empty raster #943

ben519 opened this issue Apr 14, 2014 · 3 comments · Fixed by #1077

Comments

@ben519
Copy link

ben519 commented Apr 14, 2014

When I try to do

ggplot(data.frame(x=c(1,2),y=c(1,2),z=c(1.5,1.5)),aes(x=x,y=y,color=z)) +
  geom_point()

I get the error "Error in grid.Call.graphics(L_raster, x$raster, x$x, x$y, x$width, x$height, : Empty raster"

I described this issue in a little more detail here http://stackoverflow.com/questions/23003527/weird-ggplot2-error-empty-raster

@rvernica
Copy link

Here is another case which triggers the same error:

R version 3.1.1 (2014-07-10)
Platform: x86_64-redhat-linux-gnu (64-bit)

library(ggplot2)
d <- data.frame(x=1, y=10, z=260)
ggplot(d, aes(x, y)) + geom_tile(aes(fill=z)) ## Works properly

d <- data.frame(x=1, y=10, z=261)
ggplot(d, aes(x, y)) + geom_tile(aes(fill=z))
Error in grid.Call.graphics(L_raster, x$raster, x$x, x$y, x$width, x$height,  : 
  Empty raster

@krlmlr
Copy link
Member

krlmlr commented Mar 31, 2015

According to the stack trace, this is probably a grid issue, and ggplot2 hardly can do anything about it:

 1: print(list(data = list(x = 1, y = 10, z = 261), layers = list(<envi
 2: print(list(data = list(x = 1, y = 10, z = 261), layers = list(<envi
 3: print.ggplot(list(data = list(x = 1, y = 10, z = 261), layers = lis
 4: grid.draw(gtable)
 5: grid.draw.gtable(gtable)
 6: grid.draw(gt)
 7: grid.draw.gTree(gt)
 8: recordGraphics(drawGTree(x), list(x = x), getNamespace("grid"))
 9: drawGTree(x)
10: grid.draw(x$children[[i]], recording = FALSE)
11: grid.draw.gTableChild(x$children[[i]], recording = FALSE)
12: NextMethod()
13: grid.draw.gtable(x$children[[i]], recording = FALSE)
14: grid.draw(gt)
15: grid.draw.gTableChild(gt)
16: NextMethod()
17: grid.draw.gTree(gt)
18: recordGraphics(drawGTree(x), list(x = x), getNamespace("grid"))
19: drawGTree(x)
20: grid.draw(x$children[[i]], recording = FALSE)
21: grid.draw.gTableChild(x$children[[i]], recording = FALSE)
22: NextMethod()
23: grid.draw.gtable(x$children[[i]], recording = FALSE)
24: grid.draw(gt)
25: grid.draw.gTableChild(gt)
26: NextMethod()
27: grid.draw.gTree(gt)
28: recordGraphics(drawGTree(x), list(x = x), getNamespace("grid"))
29: drawGTree(x)
30: grid.draw(x$children[[i]], recording = FALSE)
31: grid.draw.gTableChild(x$children[[i]], recording = FALSE)
32: NextMethod()
33: grid.draw.grob(x$children[[i]], recording = FALSE)
34: recordGraphics(drawGrob(x), list(x = x), getNamespace("grid"))
35: drawGrob(x)
36: drawDetails(x, recording = FALSE)
37: drawDetails.rastergrob(x, recording = FALSE)
38: grid.Call.graphics(L_raster, x$raster, x$x, x$y, x$width, x$height,

The function grid.Call.graphics is part of the grid namespace and simply calls a C implementation where the error probably occurs.

@krlmlr
Copy link
Member

krlmlr commented Mar 31, 2015

I stand corrected, it seems to be a ggplot2 issue after all. It looks like the color scale is not drawn correctly when the continuous scale uses only one color. The code below works:

d <- data.frame(x=1, y=10, z=260)
ggplot(d, aes(x, y)) + geom_tile(aes(fill=z)) + scale_fill_continuous(guide=FALSE)
d <- data.frame(x=1, y=10, z=261)
ggplot(d, aes(x, y)) + geom_tile(aes(fill=z)) + scale_fill_continuous(guide=FALSE)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants