1

I have been using the tutorials for R on clclismo and I am now at this point, where I am trying to plot points on to another plot using the instructions on the tutorial.

> plot(x,y,xlab="Independent",ylab="Dependent",main="Random Stuff")
> points(x1,y1,col=2,pch=3)
> points(x2,y2,col=4,pch=5)

The first plots as expected, but the latter two do not. The plot simply remains as is. No error is thrown up either. Any ideas?

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
  • Maybe try `par(new=TRUE)` after the plot() and the two points() – erasmortg Jul 31 '15 at 18:30
  • Works fine. Empty value for`x1`, `x2` in the code? By the way, one situation should be noticed. `pch = 1` for `pdf()` devices writting to pdf file, it won't show points correctly. For `pch`, the default value is `1`. For `pdf()`, the default value of `useDingbats` is `TRUE`. To solve this issue, set `pdf(file="t.pdf", useDingbats=FALSE)`. [DOC 1](https://stackoverflow.com/questions/14347362/r-pch-plotting-in-illustator-as-q/14347377#14347377), [DOC 2](https://tolstoy.newcastle.edu.au/R/e6/devel/09/01/0216.html), [DOC 3](https://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/pdf.html) – Nick Dong Aug 03 '20 at 04:33

1 Answers1

2

Works for me. plot produces an image and points add points to the existing plot. This is the intended behavior.

x <- rnorm(10,sd=5,mean=20)
y <- 2.5*x - 1.0 + rnorm(10,sd=9,mean=0)

x1 <- runif(8,15,25)
y1 <- 2.5*x1 - 1.0 + runif(8,-6,6)

x2 <- runif(8,15,25)
y2 <- 2.5*x2 - 1.0 + runif(8,-6,6)

plot(x,y,xlab="Independent",ylab="Dependent",main="Random Stuff",xlim=c(0,30),ylim=c(0,100))
points(x1,y1,col=2,pch=3)
points(x2,y2,col=4,pch=5)
Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197