USGS-R / gsplot

plotting foundation for timeseries reporting
Other
6 stars 14 forks source link

print issue with layout + functions #404

Open lindsayplatt opened 7 years ago

lindsayplatt commented 7 years ago

Despite the fact that none of my examples showed this during our 10 min meeting - this is an issue! layout doesn't work when the plot object is returned from a function because of the on.exit(dev.flush()) line in print.R (works when you comment that out). When the creation of a new gsplot object is outside of the function, it is fine. But when it's inside the function, the layout is ignored.

Works:

makeSimplePlot2 <- function(g1){
    g1 <- g1 %>%
        lines(1:9, seq(1,3, by=0.25),
              legend.name="second line") %>% 
        axis(side=2, at=1:10)
    return(g1)
}

g1 <- gsplot()
layout(matrix(1:2, 1, 2))
makeSimplePlot2(g1)
makeSimplePlot2(g1)

image

Doesn't work:

makeSimplePlot1 <- function(){
    g1 <- gsplot() %>%
        lines(1:9, seq(1,3, by=0.25),
              legend.name="second line") %>% 
        axis(side=2, at=1:10)
    return(g1)
}

layout(matrix(1:2, 1, 2))
makeSimplePlot1()
makeSimplePlot1()

image

lindsayplatt commented 7 years ago

@ldecicco-USGS @jiwalker-usgs @wdwatkins here's the example that I was trying to show - sorry I didn't copy the correct one into the meeting event.

lindsayplatt commented 7 years ago

jiwalker - might be messing with other stuff. We don't know