79098535

Date: 2024-10-17 14:27:27
Score: 1
Natty:
Report link

Since a ggplot is a list you can stick to base R and ggplot2 and use lapply to add a layer many times. Here is an example with a data.frame for input, but that could just as easily be a list of lists or some other object you like better.

library(ggplot2)
parsdf <- data.frame(int = c(0:2), slope = c(1,1,-1))
ggplot() +
  xlim(0, 1) +
  lapply(seq_len(nrow(parsdf)), function(i) {
    geom_function(fun = function(x) parsdf[i, "int"] + parsdf[i, "slope"]*x)
  })

enter image description here

Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: jsumner