jianhong / trackViewer

A bioconductor package with minimalist design for drawing elegant tracks or lollipop plot
https://jianhong.github.io/trackViewer/
62 stars 15 forks source link

Get lollipop plot to display multiple pin shapes with height/ score #38

Closed nuttynutmore closed 2 months ago

nuttynutmore commented 2 months ago

Hi there,

Thank you for this easy to use and well-maintained tool.

I have a question about plotting height/ score.

For reference, I am plotting the breakpoints of structural variants and using pin shape and colour to annotate rearrangement partner (colour) and whether or not the same variant is found in multiple sample types (pin shape). To tidy my visuals, I would like to take advantage of the height feature in the lollipop plot.

Currently, if you use "score" to plot height on the lollipop plot, you only get one pin shape in the plot. What I would like to know, is it possible to plot multiple pin shapes (and colours)? I have read all the vignettes and looked at the code, but can't seem to find a way to do this.

Here is an illustration of what I currently have, and what I would like to do (mocked up in illustrator).

lollipopPlot_desiredOP 001

Any clues or tips would be greatly appreciated. Kind regards, nuttynutmore

jianhong commented 2 months ago

I just submitted some change into development version to make it possible. Let me if it does not work for you.

BiocManager::install('jianhong/trackViewer')
packageVersion('trackViewer') # 1.41.3
library(trackViewer)
SNP <- c(10, 12, 1400, 1402)
features <- GRanges("chr1", IRanges(c(1, 501, 1001),
width=c(120, 400, 405),
names=paste0("block", 1:3)))
SNP <- c(10, 100, 105, 108, 400, 410, 420, 600, 700, 805, 840, 1400, 1402)
sample.gr <- GRanges("chr1", IRanges(SNP, width=1, names=paste0("snp", SNP)))
sample.gr$score <- sample.int(9, size=length(sample.gr), replace = TRUE)
available.shapes <- c("circle", "square", "diamond",
"triangle_point_up", "triangle_point_down")
sample.gr$shape <- lapply(sample.gr$score, function(s){
  sample(available.shapes, size = s, replace = TRUE)
})
sample.gr$color <- lapply(sample.gr$score, function(s){
  sample.int(7, size = s, replace = TRUE)
})
lolliplot(sample.gr, features, type="circle",
          lollipop_style_switch_limit = max(sample.gr$score))
nuttynutmore commented 2 months ago

Thank you- that works. Looks amazing!