@@ -115,16 +115,12 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all",
115
115
# https://github.com/hadley/ggplot2/blob/0cd0ba/R/plot-build.r#L18-L92
116
116
# ------------------------------------------------------------------------
117
117
118
- # create a viewport so we can convert relative sizes correctly
119
- # if height/width not specified, it is estimated from current viewport (npc)
120
- widthVP <- width %|| % unitConvert(grid :: unit(1 , " npc" ), " pixels" , " width" )
121
- heightVP <- height %|| % unitConvert(grid :: unit(1 , " npc" ), " pixels" , " height" )
122
- # assume 96 dots per inch...mm2pixels also does this....
123
- vp <- grid :: viewport(
124
- width = grid :: unit(widthVP * 72.27 / 96 , " points" ),
125
- height = grid :: unit(heightVP * 72.27 / 96 , " points" )
126
- )
127
- grid :: pushViewport(vp , recording = FALSE )
118
+ # open a new graphics device, so we can convert relative sizes correctly
119
+ # if height/width is not specified, estimate it from the current device
120
+ deviceWidth <- width %|| % unitConvert(grid :: unit(1 , " npc" ), " pixels" , " width" )
121
+ deviceHeight <- height %|| % unitConvert(grid :: unit(1 , " npc" ), " pixels" , " height" )
122
+ tmpPlotFile <- tempfile(fileext = " .png" )
123
+ grDevices :: png(tmpPlotFile , width = deviceWidth , height = deviceHeight )
128
124
129
125
130
126
p <- ggfun(" plot_clone" )(p )
@@ -682,7 +678,10 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all",
682
678
gglayout $ width <- width
683
679
gglayout $ height <- height
684
680
685
- grid :: popViewport()
681
+ # we're now done with converting units, turn off the device,
682
+ # and remove the temporary file
683
+ grDevices :: dev.off()
684
+ unlink(tmpPlotFile )
686
685
687
686
l <- list (
688
687
data = setNames(traces , NULL ),
0 commit comments