How To Get The Gene Name Interactively In A R Plot
3
3
Entering edit mode
11.5 years ago
Tky ★ 1.0k

I have created a volcano plot to overview the differential expressed genes in microarray data using R.

I am wondering is there a convenient way to identify which gene does the dot represents without go to the raw data,

for example, hover the mouse on a dot and the gene name will be shown.

Many thanks in advance,

r plot visualization gene-expression • 16k views
ADD COMMENT
3
Entering edit mode
ADD REPLY
0
Entering edit mode

Hi, thanks for the link, it seems very interesting !

ADD REPLY
0
Entering edit mode

if using ggplot, check geom_text!!

ADD REPLY
0
Entering edit mode

I use plot at this moment, but definiately will take a look at geom_text when use ggplot.

ADD REPLY
5
Entering edit mode
11.5 years ago
Michael 55k

Here is an overview of some alternatives: http://www.statmethods.net/advgraphs/interactive.html

See also the Imagemap package .

The easiest way to get started is possibly using the identify function in R directly, it is not as interactive as one might wish, but it serves its purpose if there are not too many points:

mydata = matrix(rnorm(100), ncol=2, dimnames=list(rows=paste('gene', 1:50), cols=c("x","y")))
plot(mydata)
identify(x=mydata[,1], y=mydata[,2], label=rownames(mydata))

Now, click on points and the label will be added as text to the plot. Right-clicking ends it. Tip: If you click to the right of a point, the label will appear on the right, if clicking below, below, etc. However, for a large number of points this might become very clumsy, then using locator as described below might be a better option.

If you want to work with ranged selection, you can use the locator() function, which returns raw coordinates of your clicks and use function matchpt {Biobase} to find the points closest to your clicks.

plot(mydata)
clicks = locator()
matchpt(cbind(clicks$x, clicks$y), mydata)
  index   distance
 1    38 0.10874959
 2    44 0.13085363
 3     4 0.16094422
 4    48 0.06573644
 5    10 0.07867303

This might look low-tech, but in contrast to more interactive methods works out of the box, while anything else has additional dependencies.

ADD COMMENT
0
Entering edit mode

The identify will be more than enough :-) big thanks!

ADD REPLY
1
Entering edit mode
8.2 years ago
steve ★ 3.5k

The R Plot.ly library is now available for R and makes it very easy to create an interactive plot like this. I have just recently made a post showing how to create your volcano plot using it. With my example, the gene name will be visible when you mouse over a point on the plot, just as you have requested. See this post here: Creating Interactive Volcano Plots with R and Plot.ly

ADD COMMENT
1
Entering edit mode
8.2 years ago

This is also super easy if you are already good with ggplot as plotly has added a library/function to do just this.

All you need to do is make sure that your 'text' aesthetic is the text of interest.

library(ggplot2)
library(plotly)

## given test.df your data.frame with interesting values to be plotted
head(test.df)
  gene       logFC         pval
1  abo  0.22934272 9.899770e-04
2 ade2 -0.35035923 5.206969e-05
3 ade3 -0.66402834 4.417076e-12
4  aop -0.08875994 1.603035e-01
5  aub -0.26260633 1.136509e-06
6 BicD  0.22848615 5.822924e-06
  
## create ggplot plot
p <- ggplot(test.df,aes(x=-log10(pval),y=logFC,text=gene)) + geom_point()

## visualize plot with plotly
ggplotly(p)

This should cause an html page to pop out with a plot of logFC vs. pval and the ability to mouse over points and display the gene corresponding to said values.

ADD COMMENT

Login before adding your answer.

Traffic: 1707 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6