[R] How to generate scatterplot - with a twist
Marc Schwartz
marc_schwartz at me.com
Fri Oct 1 22:28:17 CEST 2010
On Oct 1, 2010, at 10:41 AM, thernubblet wrote:
>
> Hi. I would like to make a scatterplot where all of the points are evenly
> spaced from each other - however, they are all the same size and occupy the
> entire graph. For example:
>
> x = rep(c(1:10), 10)
> y = rep(c(10:1), each = 10)
> plot(x, y, pch = 0)
>
> Gives me a scatter plot with 100 square points each evenly spaced between
> each other. But these points don't fill up the entire space and if I try to
> change the 'cex' value, the points on the edges get messed up. I was
> wondering if there was a way to fill up the entire space (all of the edges
> of the little squares are touching each other) and each individual square is
> the same size. Any help will be greatly appreciated!
Is this along the lines of what you might be looking for:
x <- 0.5:10.5
y <- 0.5:10.5
plot(x, y, type = "n", xaxs = "i", yaxs = "i")
grid(10, 10, lty = "solid", col = "black")
You can get the same effect (intersecting horizontal and vertical lines) by using ?abline and setting 'h' and 'v' to the values that you require:
x <- 0.5:10.5
y <- 0.5:10.5
plot(x, y, type = "n", xaxs = "i", yaxs = "i")
abline(v = 0.5:10.5)
abline(h = 0.5:10.5)
See ?grid and also look at 'xaxs' in ?par.
You can also add additional content to the existing plot by then using functions such as ?points, ?lines, ?segments, etc.
HTH,
Marc Schwartz
More information about the R-help
mailing list