exaexa / scattermore

very fast scatterplots for R
https://exaexa.github.io/scattermore/
GNU General Public License v3.0
243 stars 7 forks source link

Suggestion: ability to plot lines #1

Closed davnovak closed 2 years ago

davnovak commented 4 years ago

Thanks a lot, scattermore is splendid!

Here is a suggestion, straight out of my wish list: I would appreciate the ability to plot lines using scattermore. This is not possible now. I include a chunk of code showing the base graphics approach which would be mimicked.

a      <- c(2, 3)
b      <- c(5, 7)
coords <- rbind(a, b)

## base graphics
plot(coords, xlim = c(0, 10), ylim = c(0, 10), type = 'l')

Temporary solution

Now, if anybody else stumbles upon this problem, it can be circumvented by doing something like this:

## scattermore with interpolation
N      <- 500
dots   <- apply(coords, 2, function(x) seq(x[1], x[2], length.out = N))
scattermore::scattermoreplot(dots, xlim = c(0, 10), ylim = c(0, 10))

Or, if we're dealing with a lot of lines and the interpolation step would require using a lot of for-loops, computing the coordinates of each dot can be done via Rcpp. This is how I currently solve the problem.

Cheers

exaexa commented 4 years ago

I don't want to implement the linepainting for various widths of lines (b/c that already sucks a lot in the code); I'm instead going to try the gigascatter way (kernelizing the pixels to make them look bigger, which should work nicely on lines as well). It's also going to be much faster for plotting lots of big points^H^H^H^H^H^H^H lines.

exaexa commented 4 years ago

Putting this here to motivate myself further: https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm

exaexa commented 2 years ago

Some update: there's ongoing work on scattermore "version 2" now, merging some extra ideas from GigaScatter. Lines (and likely some other extra shapes) will be supported.

brunomioto commented 2 years ago

+1 !!

exaexa commented 2 years ago

spoiler alert: Image Pasted at 2022-7-10 17-13