Reputation: 3336
So I have a plot in R, but the points seem to be offset by a small amount... (maybe by 1 point to the right).
This is my code:
x <- 0:30
db<-dbinom(x, 30, 0.30)
plot(x, db, type = "h", ylab=NULL)
lines(x, db, type = "l", lty=2, ylab=NULL)
points(db, y=NULL, col="red")
And here is the plot:
Am I calling the points() functions incorrectly or missing something out? I can't find anything on here or google... Any guidance would be appreciated. Thanks in advance.
Upvotes: 1
Views: 2252
Reputation: 7895
You need to set both x and y to align it properly.
Change
points(db, y=NULL, col="red")
To
points(x, db, col="red")
Upvotes: 1
Reputation: 7592
By default, if you supply no y
argument, points()
will plot the points at x=1
to x=length(data)
. To fix that, modify you code as follows:
points(x, y = db, col="red")
Upvotes: 5