79091732

Date: 2024-10-15 21:04:48
Score: 0.5
Natty:
Report link

An example of what how you tried to make the plot would help people answer your question. I am not immediately sure what you want to show with the data you posted so I adapted an example from the viridis package using some random data. There are lots of examples of how to do this sort of thing online that should help: https://www.data-to-viz.com/graph/circularbarplot.html

library(ggplot2)
df <- data.frame(
  individual_gene = paste0("Gene ", seq(1,60)),
  group = rep(1:12, 5),
  value1 = runif(60, 1, 3),
  value2 = runif(60, 1, 3),
  value3 = runif(60, 1, 3)
)
df <- reshape2::melt(df, id.vars = c("individual_gene", "group"),
               measure.vars = paste0("value", 1:3))
df <- df[order(df$group, df$individual_gene),]
df$id <- rep( seq(1, nrow(df)/3) , each=3)

gene_labels <- aggregate(id ~ group, df, min)
colnames(gene_labels)[2] <- "start"
gene_labels$end <- aggregate(id ~ group, df, max)$id
gene_labels$position <- sapply(seq_len(nrow(gene_labels)), function(i) {
  mean(as.numeric(gene_labels[i, c("start", "end")]))
  })
gene_labels$pct <- sapply(gene_labels$group, function(grp) {
  sum(df[df$group == grp, "value"]) / sum(df$value)
})
angle <- 90 - 360 * (gene_labels$group-0.5) / 12 
gene_labels$angle <- ifelse(angle < -90, angle+180, angle)

ggplot(df) +
  geom_bar(aes(x=as.factor(id), y=value, fill=as.factor(group)), stat="identity") +
  scale_fill_manual(values = rbind(viridis::plasma(6, end = 0.9), viridis::mako(6, end = 0.9))) +
  ylim(-10, NA) +
  theme_minimal() +
  theme(
    legend.position = "right",
    axis.text = element_blank(),
    axis.title = element_blank(),
    panel.grid = element_blank(),
    plot.margin = unit(rep(-1,4), "cm") 
  ) +
  labs(fill = "Group") +
  coord_polar()+
geom_text(data=gene_labels, aes(x = position, y = -1, label=paste0(round(pct, 2), "%")),
          hjust = rep(c(1, 0), each = 6),
          angle = gene_labels$angle,
          alpha=0.8, size=3)

enter image description here

Reasons:
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: jsumner