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

Continuous color scale with ggplot2 #132

Closed
krlmlr opened this issue Jan 20, 2016 · 2 comments
Closed

Continuous color scale with ggplot2 #132

krlmlr opened this issue Jan 20, 2016 · 2 comments

Comments

@krlmlr
Copy link
Collaborator

krlmlr commented Jan 20, 2016

library(ggplot2)
library(tikzDevice)
jpeg()
tikz()
recordGraphics({ggplot(data.frame(x=1,y=1,color=1), aes(x=x,y=y,color=color)) +
    geom_point() +
    theme_minimal() +
    theme(axis.text = element_blank(), axis.title = element_blank(), legend.text = element_blank())
}, list(), getNamespace("graphics"))
# dev.off()
# dev.off()

raises:

Error in UseMethod("depth") : 
  no applicable method for 'depth' applied to an object of class "NULL"
33: depth(path)
32: upViewport(recording = FALSE)
31: grid.draw.gTableChild(x$children[[i]], recording = FALSE)
30: grid.draw(x$children[[i]], recording = FALSE)
29: drawGTree(x)
28: recordGraphics(drawGTree(x), list(x = x), getNamespace("grid"))
27: grid.draw.gTree(gt)
26: NextMethod()
25: grid.draw.gTableChild(gt)
24: grid.draw(gt)
23: grid.draw.gtable(x$children[[i]], recording = FALSE)
22: NextMethod()
21: grid.draw.gTableChild(x$children[[i]], recording = FALSE)
20: grid.draw(x$children[[i]], recording = FALSE)
19: drawGTree(x)
18: recordGraphics(drawGTree(x), list(x = x), getNamespace("grid"))
17: grid.draw.gTree(gt)
16: NextMethod()
15: grid.draw.gTableChild(gt)
14: grid.draw(gt)
13: grid.draw.gtable(x$children[[i]], recording = FALSE)
12: NextMethod()
11: grid.draw.gTableChild(x$children[[i]], recording = FALSE)
10: grid.draw(x$children[[i]], recording = FALSE)
9: drawGTree(x)
8: recordGraphics(drawGTree(x), list(x = x), getNamespace("grid"))
7: grid.draw.gTree(gt)
6: grid.draw(gt)
5: grid.draw.gtable(gtable)
4: grid.draw(gtable) at plot.r#154
3: print.ggplot(yy$value)
2: print(yy$value)
1: source("~/.active-rstudio-document", echo = TRUE)

The error is gone when color = color is omitted or replaced by color = factor(color). It's crucial to have a device open to reproduce this issue (can be tikz, png, pdf, jpeg, doesn't matter). On the other hand, if the current device isn't tikz, the issue cannot be reproduced.

EDIT: If I return immediately from TikZ_Raster(), the error doesn't occur. Will investigate.

@krlmlr
Copy link
Collaborator Author

krlmlr commented Jan 20, 2016

I'm pretty sure this is caused by tikz_writeRaster() opening a new PNG device for creating a PNG file. It might be that the graphics code isn't fully reentrant in this particular use case. I'll try changing this to png::writePNG(), let's hope the image differences won't be too large.

@yihui: I'm not really familiar with recording and replaying of plots. The tikzDevice creates an auxiliary PNG file for each raster grob, through the C function TikZ_Raster() which calls the R function tikz_writeRaster(). Do you think the current implementation (short of re-opening a device for this) is the right way to do it?

@yihui
Copy link
Collaborator

yihui commented Jan 20, 2016

Sorry I have no idea here.

krlmlr added a commit that referenced this issue Feb 3, 2016
- Use `png::writePNG()` to output raster images to avoid reentrancy issues with capturing and playback and to reduce size of raster images. The `tikzRasterResolution` option is now obsolete (#132).
krlmlr pushed a commit that referenced this issue Feb 6, 2016
Features
---

- Use `png::writePNG()` to output raster images to avoid reentrancy issues with capturing and playback and to reduce size of raster images. The `tikzRasterResolution` option is now obsolete (#132).

Bug Fixes
---

- The setting `sanitize = TRUE` works even if the `tikzDevice` package is not attached to the search path (#129).

Internal
---

- Update `ggplot2` results to account for minor differences due to the package's update (#131).
- Add test for combined rotation and reflection of raster images.
- Add tracing code to the beginning of almost every C function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants