scattermore
scattermore copied to clipboard
How to add points to existing plot with scattermoreplot?
I created a plot with scattermoreplot, and want to add additional points in every for loop iteration. Is there such functionality such as adding points() to a plot() plot?
Hi, yes there is. There are a few ways to do that:
- if you want to see the intermediate results, you can use the plain
scattermore()function to plot into a bitmap and then add the bitmap to the output using e.g. R functionrasterImageor so. - if you just need to assemble multiple pieces of input together that aren't available at the same time, you may use
scatter_points_rgbwtto rasterize the point set into an intermediate format (see https://exaexa.github.io/scattermore/reference/scatter_points_rgbwt.html), merge multiple rasters usingmerge_rgbwt(https://exaexa.github.io/scattermore/reference/merge_rgbwt.html) and in the end convert the whole thing to a plottable bitmap using these 2 things: https://exaexa.github.io/scattermore/reference/rgbwt_to_rgba_int.html and https://exaexa.github.io/scattermore/reference/rgba_int_to_raster.html
The best way probably depends on your use-case -- what are (roughly) the point amounts that you want to add in each iteration?
PS I just realized we also have a vignette that contains some relevant code -- the merging of the intermediate layers is described roughly around here: https://exaexa.github.io/scattermore/articles/low_level_interface.html#merging-rgbwt-and-rgba-layers
Thank you! Is it possible to pass a vector for pointsize in geom_scattermost(count_pairs_matrix, pointsize=2)? I need the points to have variable size (depending on some count). Basically I want the size of the point to increment with how many observations for that (x,y) point I got.
no, unfortunately not, the API is made for single-pixel operations only (for speed) and you are supposed to expand the points after that. (The logic there is that for actual big data, expanding single pixels is much faster than plotting lots if large points.)
The options are:
- You can use the same trick as above to plot a few layers of points with different sizes.
- You might want to use the histogram functionality instead, and then expand and colorize the histogrammed points with a palette of just 2 colors. (See https://exaexa.github.io/scattermore/articles/low_level_interface.html#coloring-densities ).
As a quick question, how many points (roughly) are you plotting in total? Scattermore is specialized for amounts where point sizes typically do not matter anymore; which is exactly why doing "precise" stuff like this gets complex.
Cf. this issue: https://github.com/exaexa/scattermore/issues/18