ggplot2: Add points to geom_line

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.

Answers


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))


Need Your Help

write GET URL variable to page using javascript

javascript forms encoding get

I have a form which contains a wysiwyg editor. The form data is sent to a page using a GET method in the form.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.