USGS-R / gsplot

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

additional axes inheriting side 2 #471

Closed lindsayplatt closed 7 years ago

lindsayplatt commented 7 years ago

The scale on new added axes seems dependent on side 2, which was not the case before.

plot2 <- gsplot() %>% 
    points(side=2, 1,1) %>% 
    points(side=4, 100, 100) %>% 
    points(side=6, 50,50, axes=FALSE)
par(mar=c(5,4,4,6))
plot2
axis(side=4, at=seq(30,70,by=10), line=3, las=1)

v0.7.1 printed this: image

But v0.8.0 shows this: image

The red circle shows where the axis is. Since the new axis is from 30-70, it shows up as a small dot because side 2 is from 0.6-1.4.

ldecicco-USGS commented 7 years ago

Did you try append=TRUE?

jordansread commented 7 years ago

from gsplot v0.8.0,

par('usr')
[1]   1.0 100.0   0.6   1.4

from v0.7.1:

par('usr')
[1]   1 100  30  70
jordansread commented 7 years ago

in v0.8.0, this chunk of code that is run after the rendering will reset par('usr') back to what it should be for view.1.2, which is the new behavior you are seeing (instead of leaving it w/ the last rendered usr, as happened in v0.7.1).

if(!is.null(view.info)){
    default_view <- ifelse("view.1.2" %in% view.info$name, "view.1.2", view.info$name[1])
    set_frame(views, default_view)    
  }

I think this code change is related to getting the legend() call that happens next in print?

https://github.com/USGS-R/gsplot/commit/43e27b9403489dcc842bed0eb880ee04651c2e90 @ldecicco-USGS can you weigh in?

ldecicco-USGS commented 7 years ago

legend was the main reason. Also, if you added something in base R later, it would be in whatever view was last, and sometimes that was totally wrong.

For example, I know this example was fixed by adding that line:

date_vector <- seq(as.Date("2010-10-01"), as.Date("2011-09-30"), by="months")
gs <- gsplot() %>% 
  points(date_vector, 1:12)
gs

points(as.Date("2011-01-15"),2.5, col="blue", pch=20)

without switching to default, it didn't plot that last point

jordansread commented 7 years ago

seems our backdoor solution to axes > 4 might need revising, or we might need to rethink yes/no support for axes > 4?

ldecicco-USGS commented 7 years ago

The backdoor solution could probably be rejiggered (defining the par or something), but we could think more about if the current total behavior in gsplot makes sense.

jordansread commented 7 years ago

I wonder if default view should be the last view instead of the first?

jordansread commented 7 years ago

@lindsaycarr if reworking the previous solution:

plot2 <- gsplot() %>% 
    points(side=2, 1,1) %>% 
    points(side=4, 100, 100) %>% 
    points(side=6, 50,50, axes=FALSE)
par(mar=c(5,4,4,6))
plot2
plot(NA, 0, ylim = ylim(plot2, side = 6), xlim=c(0,1), axes=FALSE, ylab="", xlab="")
axis(side=4, at=seq(30,70,by=10), line=3, las=1)

would do it.

ldecicco-USGS commented 7 years ago

I think the issue was (at the time) that if you just added some ticks in axis=4, the limits for an empty view 1,4 wasn't getting the right limits. I think maybe now we fixed that?? Maybe we can test if taking that resetting of view out and leave it as the last view and see if the readme example works now? (then we need to figure out legend.

I feel like though that a lot of weird behavior was fixed with that line...so let's be very careful with a change.

jordansread commented 7 years ago

cool. agreed. Proposed backdoor solution ☝️

lindsayplatt commented 7 years ago

@jread-usgs that would be behavior I would expect

lindsayplatt commented 7 years ago

sorry, my github was lagging. Yes, backdoor solution that @jread-usgs provided will be good (except that it needs a par(new=TRUE)!