I have a line-plot in ggplot2 and I want to add points (=shapes) for each data row to clearly identify it. I do not(!) need a shape/point at every data-point but instead some values would be sufficient. See the following example:
library(ggplot2)
library(data.table)
d=data.table(x=seq(0, 100, by=0.1), y=seq(0,1000)))
ggplot(d, aes(x=x, y=y))+geom_line()
ggplot(d, aes(x=x, y=y))+geom_line()+geom_point()
Due to the huge number of samples, the shapes are not visible anymore but overdraw each other. I only need some of them, perhaps a equidistant spacing would look the best, but I'm open to any other solution.
You can also add some points, just thin the data with an index.
library(ggplot2)
library(data.table)
d=data.table(x=seq(0, 100, by=0.1), y=seq(0,1000))
ggplot(d, aes(x=x, y=y))+geom_line()
#Change the length parameter for fewer or more points
thinned <- floor(seq(from=1,to=dim(d)[1],length=70))
ggplot(d, aes(x=x, y=y))+geom_line()+geom_point(data=d[thinned,],aes(x=x,y=y))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With