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

Plotting outside of the plot area #9

Closed
xrobin opened this issue Jul 29, 2015 · 3 comments
Closed

Plotting outside of the plot area #9

xrobin opened this issue Jul 29, 2015 · 3 comments
Assignees

Comments

@xrobin
Copy link
Owner

xrobin commented Jul 29, 2015

Something goes wrong when setting par(mar=...), calling plot.roc, axis and plot.roc again with add=TRUE. Visible only when xlim/ylim are set (or maybe also with massive margins?)

Compare:

roc1 <- roc(aSAH$outcome, aSAH$wfns)
roc2 <- roc(aSAH$outcome, aSAH$ndka)
par(mar=c( 4, 4.5, 1, 1 ))
plot(roc1, xlim=c(0.96, 0.66), ylim=c(0.56,0.86), xaxt="n")
axis(side=1)
plot(roc2, add=T)

With:

m1.roc <- roc(aSAH$outcome, aSAH$wfns)
m2.1.roc <- roc(aSAH$outcome, aSAH$ndka)
par(mar=c( 4, 4.5, 1, 1 ))
plot(roc1, xlim=c(0.96, 0.66), ylim=c(0.56,0.86), xaxt="n")
plot(roc2, add=T)

or:

m1.roc <- roc(aSAH$outcome, aSAH$wfns)
m2.1.roc <- roc(aSAH$outcome, aSAH$ndka)
par(mar=c( 4, 4.5, 1, 1 ))
plot(roc1, xlim=c(0.96, 0.66), ylim=c(0.56,0.86), xaxt="n")
plot(roc2, add=T)
axis(side=1)
@xrobin
Copy link
Owner Author

xrobin commented Jul 30, 2015

One can produce lines outside the plotting area with code like:

roc1 <- roc(aSAH$outcome, aSAH$wfns)
roc2 <- roc(aSAH$outcome, aSAH$ndka)
par(mar=c( 4, 4.5, 1, 1 ))
opa <- par(mar=c(4, 4, 2, 2) + 0.1, mgp = c(2.5, 1, 0))
plot(roc1$specificities, roc1$sensitivities, xlim=c(0.96, 0.66), ylim=c(0.5,0.86), xaxt="n", type="l")
par(opa)
lines(roc2$specificities, roc2$sensitivities)
axis(side=1)

The question remains: why in the previous example the "out of the area" plotting happens only when axis is called between the two calls to plot - it is clearly not the case in this example.

@xrobin
Copy link
Owner Author

xrobin commented Jul 30, 2015

This is pretty much a minimum reproducible example:

x <- y <- 1:10
smallmar <- rep(0, 4)
bigmar <- c(4, 4, 2, 2)
par(mfrow=c(2, 1))

# First plot outside area
par(mar=bigmar)
plot(x, y, type="n") # l or n doesn't matter - use l to avoid re-plotting
lines(x, y)
par(mar=smallmar)
axis(side=1)
lines(x + 1, y)

# Second plot stays within plot area
par(mar=bigmar)
plot(x, y, type="n")
lines(x, y)
par(mar=smallmar)
lines(x + 1, y)
axis(side=1)

Looks like a bug upstream. If I call axis between the two calls to lines the line extends outside the plot area. It could be a weird clipping effect as described in ?clip: "Exactly when the clipping region will be reset can be hard to predict".

@xrobin
Copy link
Owner Author

xrobin commented Jul 30, 2015

Long story short, plotting outside the previous plotting area seems to be the normal behaviour when margins are updated (but one has to call axis or box to have it enforced) - after all the plotting area is updated. I do think there is nothing to change here.

Please feel free to re-open if you think otherwise.

@xrobin xrobin closed this as completed Jul 30, 2015
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

1 participant