I have the following dataset:
x = c(4, 5, 10, 30, 50, 51)
y = sqrt(x)
And I'd like to plot the data in the x-range from 5-50
plot(x,y, xlim=c(5, 50))
abline(v=c(5,50), col="red")
But still datapoints from outside of that range are visible.
Is there an easy way to tell the plot()
to tkae the limit literally.
So far I came up with two ideas:
- Remove margins of the plot (I actually like the margins, but not the data that become visible)
- Exclude the data from the variables before plotting them (in my experience that was always tedious - subset() might work when you organize your data in a data.frame)