Entering edit mode
2.2 years ago
Manuel
▴
10
Hi!
I have a dataset called final_result with the colnames
[1] "pathway" "genes_involved_in_pathway" "kit_gene_counts"
[4] "leiomyo_lipo_gene_counts" "nos_leiomyo_gene_counts" "nos_lipo_gene_counts"
[7] "genes_leiomyo_lipo" "genes_nos_leiomyo" "genes_nos_lipo"
[10] "genes_leiomyo_lipo_commonly_expressed" "genes_nos_leiomyo_commonly_expressed" "genes_nos_lipo_commonly_expressed"
gg <- ggplot(final_result, aes(x = reorder(pathway, -kit_gene_counts))) +
geom_bar(aes(y = kit_gene_counts), stat = "identity", fill = "lightblue", width = 0.5) +
geom_bar(aes(y = leiomyo_lipo_gene_counts), stat = "identity", fill = "orange", width = 0.5) +
geom_text(aes(y = kit_gene_counts, label = kit_gene_counts), vjust = -0.2, color = "black") +
geom_text(aes(y = leiomyo_lipo_gene_counts, label = leiomyo_lipo_gene_counts), vjust = -0.2, color =
"black") +
labs(title = "Concordance between Genes from Kit in Pathways and DGE genes Leiomyo Lipo", x =
"Pathway", y = "Number of Genes") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
I want for the blue bar on hover to appear genes_leiomyo_lipo_commonly_expressed value and for the orange bar on hover the genes_leiomyo_lipo value. I tried different approaches none with the desired result.
This is the current result of the code above.
Have you run
ggplotly(gg)? It looks like you might just be plotting the defaultggplotobject.In the meanwhile I found a solution but not what I want
This add value of genes_leiomyo_lipo_commonly_expressed and genes_leiomyo_lipo on hover, yet when I touch one popup per bar showing both values. Since I have two bars on top of each other I would like to add genes_leiomyo_lipo_commonly_expressed value when I hover blue bar and genes_leiomyo_lipo the orange bar
The reason why that's happening is because you're plotting
geom_bartwice rather than plotting by a group in the originalaes()call. If you usepivot_longeron your dataframe, that will simplify your code a ton and fix your problem.