1

I've made a scatterplot in R using:

par(mfrow=c(1,2))
plot(x2~x1, pch=20, col=df$colour, cex=1.5, xlim=c(-4,16), ylim=c(-4,16))
with(df, text(x2~x1, labels = df$gene, pos = 4))
plot(x4~x3, pch=20, col=df$colour, cex=1.5, xlim=c(-4,16), ylim=c(-4,16))
with(df, text(x4~x3, labels = df$gene, pos = 4))

and I get something close to what i want, but i want the Red point of interest to be at the top of the stack in the second image. I've tried re-ordering the dataframe to have the single point both first and last in the dataframe but it doesn't alter the image, the point of interst is still hidden in the second plot. Any help would be much appreciated. Thanks! image of two scatter plots

Community
  • 1
  • 1
GGD
  • 13
  • 4
  • If you're willing to use the ggplot2 package to make your charts, you can use the `order` aesthetic to specify point plotting order. Like this: http://stackoverflow.com/questions/15706281/controlling-order-of-points-in-ggplot2-in-r/29325361#29325361 – Sam Firke Dec 11 '15 at 21:25
  • Thanks Sam, i'll check this out. – GGD Dec 11 '15 at 21:28

1 Answers1

2

Add the point using points after calling the plot:

y1 <- x1[df$coulour=="red"]
y2 <- x2[df$coulour=="red"]
y3 <- x3[df$coulour=="red"]
y4 <- x4[df$coulour=="red"]

par(mfrow=c(1,2))

plot(x2~x1, pch=20, col=df$colour, cex=1.5, xlim=c(-4,16), ylim=c(-4,16))
points(y2~y1, pch=20, col="red", cex=1.5)
with(df, text(x2~x1, labels = df$gene, pos = 4))

plot(x4~x3, pch=20, col=df$colour, cex=1.5, xlim=c(-4,16), ylim=c(-4,16))
points(y4~y3, pch=20, col="red", cex=1.5)
with(df, text(x4~x3, labels = df$gene, pos = 4))
Sam Dickson
  • 5,082
  • 1
  • 27
  • 45
  • That's perfect Sam, thanks for the advice. Also thanks for the link above, I didn't come across it before posting the question. – GGD Dec 12 '15 at 21:24