box_set(x*y ~ x & y, domain(x=0:1, y=0:1), n = 4)
# approximation to the variance of a uniform [0,1] distribution
box_set((x-.5)^2 ~ x, domain(x=0:1), n=100, sum=TRUE)
# a polygon
poly <- tibble(x = c(1:9, 8:1), y = c(1, 2*(5:3), 2, -1, 17, 9, 8, 2:9))
boxes <- box_set(1 ~ x & y, poly, dx = 1)
gf_polygon(y ~ x, data = poly, color="blue", fill="blue", alpha=0.2) %>%
gf_rect((y - dy/3) + (y + dy/3) ~ (x - dx/3) + (x + dx/3),
data = boxes)
# area inside polygon
box_set(1 ~ x & y, poly, n=100)
Run the code above in your browser using DataLab