sfactor
sfactor

Reputation: 13062

In R how to control the spacing of points in a line and points plot

So I have a plot() in R with type = "o" so that I can have both line and points. But I find that there are far too many points in the more constant parts of the plot. So, is there a way for me to increase the spacing between each individual points in this plot.

Upvotes: 0

Views: 2959

Answers (4)

PaulHurleyuk
PaulHurleyuk

Reputation: 8169

I would recomend you look at the ggplot2 package for drawing graphs in R. This has several options for dealing with an over abundance of points, my favorite is including an alpha value so the reader can see the difference between one point and ten overlaid.

library(ggplot2)
d <- ggplot(diamonds, aes(carat, price)) + geom_point(alpha = 1/10)
print(d)

Upvotes: 3

Paolo
Paolo

Reputation: 2815

Similar to the advice proposed by PaulHurleyuk but using the Bioconductor geneplotter package:

source("http://bioconductor.org/biocLite.R")
biocLite("geneplotter")    
library(ggplot2)
data(diamonds)
library(geneplotter)
smoothScatter(diamonds$carat,diamonds$price)

enter image description here

Upvotes: 0

Dirk is no longer here
Dirk is no longer here

Reputation: 368261

Please see help(par) and the discussion of line types.

Edit: Or just try the following:

plot(1:10, type='n', xlim=c(1,10), ylim=c(0,7))
for (i in 1:6) lines(1:10, rep(i, 10), lty=i)

which plots six lines with the six pre-defined line types.

Upvotes: 0

Greg Snow
Greg Snow

Reputation: 49640

I would plot the lines using type='l', then go back and use the points function to add just the points that you want.

Upvotes: 4

Related Questions