The clip
function helps to set a clipping region in base graphics. For example, if I simulated a few observations in 2-d, I can plot only the observations in 4th quadrant in the following way:
dataset <- data.frame(x = runif(n = 100, min = -1, max = 1),
y = runif(n = 100, min = -1, max = 1))
plot(x = dataset, type = "n")
abline(h = 0, v = 0)
usr <- par('usr')
clip(x1 = 0, x2 = 1, y1 = -1, y2 = 0) # limits are sufficient for this toy example
points(x = dataset, pch = "x")
do.call(clip, as.list(x = usr))
Created on 2019-07-04 by the reprex package (v0.3.0)
How can I do the same in ggplot2
? I can of course filter the observations first, but I'm looking for a direct alternative.