'ggplot labels all in wrong location
I'm trying to label a dot plot, but my labels are showing up entirely in a different direction. I though it was due to repelling (tried using ggrepel)- but they are actually just in the wrong location of the dot plot. (it's a volcano plot, so there are no points in the bottom right. Here is my code:
vplot.dM.a <- ggplot(myTopHits.dM.a) +
aes(y=-log10(p_val_adj), x=avg_log2FC, label = geneID) +
geom_point(size=1) +
geom_label(data = subset(myTopHits.dNK1, avg_log2FC > 1 | avg_log2FC < -1)) +
geom_hline(yintercept = -log10(0.01), linetype="longdash", colour="grey", size=1) +
geom_vline(xintercept = 1, linetype="longdash", colour="#BE684D", size=1) +
geom_vline(xintercept = -1, linetype="longdash", colour="#2C467A", size=1) +
labs(title="Volcano plot",
subtitle = "dM.a cells") +
theme_bw()
i saw some comments on a similar issue with pie charts, but couldn't adjust it for the dotplot. any suggestions?
plot without labels

plot with labels

Solution 1:[1]
geom_text_repel function from ggrepel should put your label in the right direction. The below code should work. You can tweak the argument the function for better visualization. Also use the same global data as pointed by
teunbrand.
library(ggrepel)
geom_text_repel(
data = subset(myTopHits.dM.a, avg_log2FC > 1 | avg_log2FC < -1),
size = 5,
direction = "x",
angle = 0,
vjust = 0,
segment.size = 0.2,
arrow = arrow(length = unit(0.01, "npc"), type = "closed", ends = "first"),
nudge_y = 1 + data$avg_log2FC,
nudge_x = 1 + data$avg_log2FC,
segment.color = "black")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gyan Prakash Mishra |
