View source: R/fGetBlocksThroughWhichLineSegmentsPass.R
fGetBlocksThroughWhichLineSegmentsPass | R Documentation |
Identifies the blocks in a grid through which a line segment goes
fGetBlocksThroughWhichLineSegmentsPass( dt_ls, x_lim = c(-60, 60), y_lim = c(-40, 40), x_gap = 5, y_gap = 5 )
dt_ls |
a data.table with x, y, xend, yend, and optionally id |
x_lim |
the span of x coordinates on your grid - c(min x, max x) |
y_lim |
the span of x coordinates on your grid - c(min y, max y) |
x_gap |
the spacing between blocks of the grid on the x dim |
y_gap |
the spacing between blocks of the grid on the y dim |
library(data.table) dt_ls = rbind( data.table(x = -27, y = 7, xend = -37, yend = 22, id = 1), data.table(x = 27, y = 7, xend = 37, yend = 22, id = 2), data.table(x = 27, y = -7, xend = 37, yend = -17, id = 3), data.table(x = -27, y = -7, xend = -37, yend = -17, id = 4), data.table(x = -25, y = 25, xend = -10, yend = 35, id = 5), data.table(x = 25, y = 25, xend = 10, yend = 35, id = 6), data.table(x = 25, y = -25, xend = 10, yend = -35, id = 7), data.table(x = -25, y = -25, xend = -10, yend = -35, id = 8), data.table(x = -8, y = -20, xend = 8, yend = -20, id = 9), data.table(x = 0, y = 0, xend = 0, yend = 20, id = 10) ) dt_grids_ls = fGetBlocksThroughWhichLineSegmentsPass( dt_ls = dt_ls, x_lim = c(-60,60), y_lim = c(-40,40), x_gap = 5, y_gap = 5 ) library(ggplot2) ggplot() + geom_tile( data = dt_grids_ls, aes(x = x_block, y = y_block), fill = 'cyan', color = 'black' ) + geom_segment( data = dt_ls, aes(x = x, y = y, xend = xend, yend = yend), color = 'red', arrow=arrow(type="closed",ends="last",length=unit(0.1,"cm")) ) + coord_fixed()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.