jokergoo / circlize

Circular visualization in R
http://jokergoo.github.io/circlize_book/book/
Other
959 stars 141 forks source link

Points with error bars #386

Open bennydeslandes opened 6 months ago

bennydeslandes commented 6 months ago

Thanks for the great package!

I was wondering if it would be possible to plot points with error bars?

I'm trying to create a circos plot that divided into 6 sections (per each gene). For the first track I wanted to plot points with error bars/confidence intervals? This is an example of the structure of my dataset:

data <- data.frame(
  genes = as.factor(c("gene1", "gene2", "gene3", "gene4", "gene5", "gene6", "gene1", "gene2", "gene3", "gene4", "gene5", "gene6")),
  OR = c(0.5, 1.2, 1.3, 1.7, -0.3, -0.9, 0.5, 1.2, 1.3, 1.7, -0.3, -0.9), 
  upper_CI = c(0.7, 1.4, 1.5, 1.9, -0.1, -0.7, 0.7, 1.4, 1.5, 1.9, -0.1, -0.7),
  lower_CI = c(0.3, 1.0, 1.1, 1.5, -0.5, -1.1, 0.3, 1.0, 1.1, 1.5, -0.5, -1.1),
  pval = c(0.01, 0.01, 0.005, 0.00001, 0.1, 0.6, 0.01, 0.01, 0.005, 0.00001, 0.1, 0.6),
  label = c("ct1tp1", "ct1tp2", "ct2tp1", "ct2tp2", "ct3tp4", "ct5tp8", "ct8tp2", "ct1tp9", "ct3tp5", "ct9tp9", "ct6tp9", "ct11tp8")
)

Thank you in advance

bennydeslandes commented 6 months ago

I tried to adapt a code from a previous question (https://github.com/jokergoo/circlize/issues/361) but it just turned out weird - the error bars are inside the points

circos.initialize(letters[1:6], xlim = c(0, 10))
circos.track(ylim = c(0, 1.2), panel.fun = function(x, y) {
  value = runif(10)
  mid = 1:10 - 0.5

  circos.points(mid, value, pch = 16, col = "blue", cex = 2)

  error = value * 0.2
  circos.segments(mid, value - error, mid, value + error, col = "red")
  circos.segments(mid - 0.15, value - error, mid + 0.15, value - error, col = "red")
  circos.segments(mid - 0.15, value + error, mid + 0.15, value + error, col = "red")
})
circos.clear()
bennydeslandes commented 6 months ago

Never mind! I think I've found how to fix it (change the point size)

circos.initialize(letters[1:6], xlim = c(0, 10))
circos.track(ylim = c(0, 1.2), panel.fun = function(x, y) {
  value = runif(10)
  mid = 1:10 - 0.5

  circos.points(mid, value, pch = 16, col = "black", cex = 0.5)

  error = value * 0.2
  circos.segments(mid, value - error, mid, value + error, col = "black")
  circos.segments(mid - 0.15, value - error, mid + 0.15, value - error, col = "black")
  circos.segments(mid - 0.15, value + error, mid + 0.15, value + error, col = "black")
})
circos.clear()

Thanks for the great package 😄