ggbio icon indicating copy to clipboard operation
ggbio copied to clipboard

heatmap in circular view, as "geom"?

Open tengfei opened this issue 12 years ago • 4 comments

Now of course you can use rect geom to mimic heat map easily, maybe a more general heartmap geom should be there for circular view too.

tengfei avatar Apr 23 '12 16:04 tengfei

hello, I was trying to generate heatmap for gene density (i.e. number of genes in non-overlapping 500kb bins) in a genome and display in circular view. I was hoping to get a plot that each colored bar/box represent one 500kb bin in the genome and the color for each heatmap bar/box represents the amount of genes in that bin(i.e. the box is white if the bin contains fewer genes and the box is blue if more genes are in the bin), however it seemed that rect geom argument or the geom = "heatmap" argument was giving me back something like a scatter plot instead. Do you mind explain in more detail how to generate a heatmap on a circular plot using ggbio? Thank you very much!

XinyiZhu1007 avatar Aug 13 '16 00:08 XinyiZhu1007

Hi,

I have very similar data and aim, had to bump this old post :)

I have SNP counts as "score" in my GRanges object:

> relist(tiles.gr, tiles)
GRangesList object of length 19:
$chrA01 
GRanges object with 3005 ranges and 1 metadata column:
                seqnames            ranges strand |     score
                   <Rle>         <IRanges>  <Rle> | <numeric>
  chrA01.chrA01   chrA01       82924-92921      * |         2
  chrA01.chrA01   chrA01      92922-102920      * |         0
  chrA01.chrA01   chrA01     102921-112918      * |         0
  chrA01.chrA01   chrA01     112919-122917      * |         0
  chrA01.chrA01   chrA01     122918-132916      * |         0
            ...      ...               ...    ... .       ...
  chrA01.chrA01   chrA01 30078762-30088760      * |        14
  chrA01.chrA01   chrA01 30088761-30098759      * |         7
  chrA01.chrA01   chrA01 30098760-30108757      * |        16
  chrA01.chrA01   chrA01 30108758-30118756      * |         0
  chrA01.chrA01   chrA01 30118757-30128755      * |         4

And wanted to plot a circular heatmap based on the scores.

Did you manage to figure out how to use it @XinyiZhu1007 ?

Thanks! Cheers Jenny

JennyHTLee avatar Oct 29 '18 09:10 JennyHTLee

The code below gives me a scatterplot, like what was mentioned

ggbio() + 
  circle(tiles.gr, aes(y=score), geom = "heatmap", grid=TRUE) +  ##most inner circle
  circle(express.gr, geom = "ideo", fill = "gray70") +  ##plot genome as blocks
  circle(express.gr, geom = "scale", size = 2) +   ##add scale
  circle(express.gr, geom = "text", aes(label = seqnames), vjust = 0, size = 3) 

JennyHTLee avatar Oct 29 '18 09:10 JennyHTLee

It was achieved using geom rect (filled by score) and scale_fill_gradient:

ggbio() + 
  circle(tiles.gr, aes(fill=score, colour=NULL), geom="rect")+ ##most inner circle
  scale_fill_gradient(low = "white", high = "red")  +
  circle(express.gr, geom = "ideo", fill = "gray70") +  ##plot genome as blocks
  circle(express.gr, geom = "scale", size = 2) +   ##add scale
  circle(express.gr, geom = "text", aes(label = seqnames), vjust = 0, size = 3)  

rplot

JennyHTLee avatar Oct 29 '18 10:10 JennyHTLee