1

My question is how do I make the scatter plot to show the color for over-expressed and under-expressed genes. At the moment scatter plot shows only black color. I would like to indicate on the graph in red color over-expressed genes and under-expressed genes on blue. I am attaching snapshot of the scatter plot and the . I need help with the code. It is in R. This code produces scatter plot that only shows everything in black.

Scatter plot showing one group versus another group

dataA <- rowMeans(filtered_condensed$E[,7:9])
dataB <- rowMeans(filtered_condensed$E[,10:12])

par(family="mono")

meanX = dataA
meanY= dataB


plot(meanX, meanY, main = "Expression in OPCs vs oligodendrocyte ",
    xlab="OPCs log2 expression: group1", ylab="oligodendrocyte log2 expression: group2", cex=0.5, cex.lab= 0.9, title(cex.main=2, font.main=7))
abline(-1, 1, col='purple', lty="dashed")
abline(1, 1, col="purple", lty="dashed")

image output

MrFlick
  • 195,160
  • 17
  • 277
  • 295
Ania
  • 21
  • 6
  • 1
    When asking for plotting help you should provide some form of [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data. Provide a link to an image describing what you are trying to achieve. – MrFlick Mar 23 '17 at 19:38
  • hi. I am not sure why it did not work, but I attached few images of my code and the resulting scatter plot. – Ania Mar 23 '17 at 20:10
  • I am new to this platform. The code at the moment is as follows – Ania Mar 23 '17 at 20:12
  • http://imgur.com/a/sTkHv - here is a link to the image of the code and the graph – Ania Mar 23 '17 at 20:25
  • thanks for editing my post! here is an example of the graph with red and blue gene expression indicated ... I am not sure how to alter the code to do it the same for the scatter plot. http://imgur.com/a/sTkHv – Ania Mar 23 '17 at 20:33
  • We are NOT your data entry staff. Post code as text in an [edit] to your question. – IRTFM Mar 23 '17 at 22:35

1 Answers1

1

I'll add some sample data here to test:

set.seed(23)
meanX <- runif(1000)
meanY <- meanX + rnorm(1000)

Since you have have slopes of 1 at different intercepts, you can easily calculate which are above and below the lines by looking at the different between the X and Y values. Then I just drew colored points on top of the extreme values

plot(meanX, meanY, main = "Expression in OPCs vs oligodendrocyte ",
    xlab="OPCs log2 expression: group1", 
    ylab="oligodendrocyte log2 expression: group2", 
    cex=0.5, cex.lab= 0.9, title(cex.main=2, font.main=7))
abline(-1, 1, col='purple', lty="dashed")
abline(1, 1, col="purple", lty="dashed")
above <- meanY-meanX > 1
points(meanX[above], meanY[above], col="red", cex=0.5)
below <- meanY-meanX < -1
points(meanX[below], meanY[below], col="blue", cex=0.5)

This produces the following plot

enter image description here

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • thanks a lot . I corrected my plot already. It looks like this at the moment. How do I change the x-axis dimensions? I am at the moment using xlim=c(6, 20) and this code fails to be applied to the graph. Please check current photo of the graph: http://imgur.com/a/sTkHv – Ania Mar 23 '17 at 21:57
  • how do you post a code? Do you close the code using '' and then it is posted under the gray area? – Ania Mar 24 '17 at 00:53
  • Where exactly are you putting the `xlim=` command? It needs to go in the first call to `plot()`. Seems unlikely it would be ignored. You shouldn't post code in comments but you can format text as code as I did with xlim above by surrounding it in single back-ticks. – MrFlick Mar 24 '17 at 20:12
  • `plot(meanX, meanY, main = "Expression in OPCs vs oligodendrocyte ", xlab="OPCs log2 expression: group1", ylab="oligodendrocyte log2 expression: group2", cex=0.5, cex.lab= 0.9, title(cex.main=2, font.main=7), xlim=c(6, 20))` here is the way I write the code and the xlim is at the end of the code and it is ignored – Ania Mar 24 '17 at 22:04
  • I can't reproduce that. If I put `xlim=c(-1,2)` into my `plot()` sample above, it works just fine. – MrFlick Mar 24 '17 at 23:12