Question: How To Get The Gene Name Interactively In A R Plot
gravatar for Tky
7.1 years ago by
Tky1000 wrote:

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,

ADD COMMENTlink modified 6 months ago by Biostar ♦♦ 20 • written 7.1 years ago by Tky1000

does that do the job Interactive and Animated Scalable Vector Graphics

ADD REPLYlink modified 7.1 years ago • written 7.1 years ago by Medhat8.7k

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

ADD REPLYlink written 7.1 years ago by Tky1000

if using ggplot, check geom_text!!

ADD REPLYlink written 7.1 years ago by Sukhdeep Singh10k

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

ADD REPLYlink written 7.1 years ago by Tky1000
gravatar for Michael Dondrup
7.1 years ago by
Bergen, Norway
Michael Dondrup47k wrote:

Here is an overview of some alternatives:

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")))
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.

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 COMMENTlink modified 7.1 years ago • written 7.1 years ago by Michael Dondrup47k

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

ADD REPLYlink written 7.1 years ago by Tky1000
gravatar for steve
3.8 years ago by
United States
steve2.6k wrote:

The R 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

ADD COMMENTlink modified 3.8 years ago • written 3.8 years ago by steve2.6k
gravatar for benformatics
3.8 years ago by
ETH Zurich
benformatics1.6k wrote:

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.


## given test.df your data.frame with interesting values to be plotted
  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

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 COMMENTlink modified 3.8 years ago • written 3.8 years ago by benformatics1.6k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1386 users visited in the last hour