scattermore icon indicating copy to clipboard operation
scattermore copied to clipboard

geom for lines

Open roaldarbol opened this issue 6 months ago • 6 comments

Hi, seems like an amazing library!

I work with massive time series, and I saw in #1 that you have implemented support for lines that work with base plots. I was wondering whether it would be possible to create ggplot geom for it too (like geom_scatterline)?

roaldarbol avatar Apr 29 '25 12:04 roaldarbol

Hi! yeah that would actually make a total sense (even for the consistency reasons :D ). PR welcome, the main work here is likely to copypaste the other geom code and fill in the line primitives, so actually not very complicated.

I'll try to find time for this soon, but no guarantees unfortunately.

exaexa avatar Apr 29 '25 15:04 exaexa

Awesome! I had a go at it for a couple of hours:

  • scatterlines are was straightforward to implement. Two current issues:
    • We'll have to add the extra row in the end to keep the data the same length
    • The limits are currently too narrow - so they're not correctly implemented
  • geom_scatterline: It seems that the RGBW handling is different in scatter_lines_rgbwt than in scatter_points_rgbwt and it's too late and my brain is too fried to figure it out.

roaldarbol avatar Apr 29 '25 22:04 roaldarbol

Some work started in #28.

roaldarbol avatar Apr 29 '25 22:04 roaldarbol

Alright, some examples for what I would expect it to cope with. For references, there could literally be millions of data points in there!

Image Image Image

So I guess in the ggplot aes syntax both colour and group would be needed.

By the way, the first one here and the example you provided in another thread (or PR), to match ggplot terminology, those would be geom_paths, because geom_line can only move left to right.

Do you reckon that the new functions would improve rendering of the bottom one which are single lines that aren't actually overlapping anywhere, though of course there are way too many points to be visible?

roaldarbol avatar May 04 '25 14:05 roaldarbol

Can't get the following example to run with reprex, but you could use that - just crank up the n:

library(ggplot2)
library(dplyr)

n <- 100
d <- data.frame(x = seq(from = 0, to = 4*pi, length.out = n))

df <- data.frame()
for (i in 1:5){
  df <- d |> 
    mutate(id = factor(i),
           y = sin(x+(i*1.2)) + rnorm(n, sd = 0.2) + i/5) |> 
    bind_rows(df)
}

ggplot(df, aes(x = x, y = y, colour = id)) +
  geom_line()

roaldarbol avatar May 04 '25 14:05 roaldarbol

Ah OK great, that should do it for the examples, thanks!

exaexa avatar May 04 '25 20:05 exaexa