[R] Changing pch spacing]

Peter Wolf pwolf at wiwi.uni-bielefeld.de
Thu Oct 31 10:24:18 CET 2002


Wolfgang Viechtbauer wrote:

> Hello R-Helpers,
>
> plot(x, y, type="b", pch="1")
>
> plots x vs. y with both a line and the symbol "1" but how do I change
> the "spacing" of the symbol being plotted. In other words, I don't want
> to plot the "1" at every data point, but only at every kth point (things
> get too cluttered when there are many data points). Thanks in advance!
>
> --
> Wolfgang Viechtbauer

See function bplot defined below.

Peter Wolf




"bplot"<-
function(x,y,k,pch="*",space.size=1/70,space.bg="white",pch.col="black",...){
  # plot of x and y, type "b" with symbols at every k-th points  pw 10/02
  # pch:        characters to be plotted
  # space.size: size of area for the points
  # space.bg:   color of area for the points
  # pch.col:    color of the points
  plot(x,y,type="l",...)
  ind<-seq(x)[seq(x)%%k==0]; x<-x[ind]; y<-y[ind]
  wcoord<-par()$usr
  dh<-c(wcoord[2]-wcoord[1],wcoord[4]-wcoord[3])*space.size
  rect(x-dh[1],y-dh[2],x+dh[1],y+dh[2],col=space.bg,border="white")
  points(x,y,pch=pch,col=pch.col)
}

# Example:

x<-1:500;  y<-cumsum(rnorm(length(x),3,3))
k<-40
bplot(x,y,k,pch=1,space.size=1/70,space.bg="red",pch.col="green")


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list