I was wondering how I could replace the 7 line segments
that are currently showing with points
? That is, instead of the 7 black line segments
I need 7 lines of points
going from the bottom of each of the line segments
up to the curve line? (Instead of 7 line segments, I then will have 7 vertical lines of points)
Please see my R code below the picture.
A = rnorm(1e3)
B = density(A)
x = B$x ; y = (B$y)*(B$n)
plot(x, y, type = "l")
x.DEN = seq(-3, 3)
y.DEN = approx(x, y, xout = x.DEN )$y
segments(x.DEN, par("usr")[3], x.DEN, y.DEN) ## HERE I need points
One idea, if you NEED to have points would be to use mapply
to get the position of the points that you want and then lapply
to add them all to the graph. Something like this:
mypoints <- mapply(function(x, y, z) data.frame(y = seq(x, y, length.out=floor((y-x)/5)),
x = z),
x = rep(par("usr")[3], length(y.DEN)),
y = y.DEN,
z = x.DEN ,SIMPLIFY = F)
lapply(mypoints, function(z) points(x = z$x, y = z$y))
From there you can change the size/point type to whatever you want. You can also add more or less points by dividing by a lower/higher number in the length.out=...
. I chose 5 because it seemed to look good.