When I plot a sequence in a line plot in R using transparent color settings I keep getting these dots on the line. Do you have an idea why this is and how I could solve the problem?
s <-seq(1,100, by = 0.1)
plot(s, type="l",col=scales::alpha("black",0.3), lwd=3)
I tried using the lines function which resulted in the same problem.
Also, it is interesting to see how the the dots change with e.g. s <-seq(1,100, by = 0.5)
and disappear with s <-seq(1,100, by = 1)
sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS 14.3.1
Thank you for your answers.
It is the line end style that is at play here.
The "line"-plot is drawn as a series of individual lines:
(0,0) -> (1, 0.1)
(1, 0.1) -> (2, 0.2)
(2, 0.2) -> (3, 0.3)
...
At each end of the line, the default is to draw a "rounded line cap". You can see this at each extreme of the line. Two overlapping rounded caps, give the illusion of a small circle (or point).
These points are visible, because of your partial transparency.
A solution could be to try the two other options "butt" or "square":
plot(s, type="l",col=scales::alpha("black",0.3), lwd=3, lend=1)
plot(s, type="l",col=scales::alpha("black",0.3), lwd=3, lend=2)
See the lend
parameter in ?par
.