Adding labels to end of line in ggplot2 in R

164 Views Asked by At

I am producing a lollipop graph in ggplot2 in R using dot_plot. However I would like to add one label to the end of each line to indicate each line represents 1 SNP. I would like the label to be at 180 degrees (the direction of the geom_line grouping) in the image and be at the bottom of each geom_line. It can be outside of the graph lines. I have tried many of the examples from previous posts here regarding labelling lines but can't seem to get this correct and either end up with lots of the same label for the geom_line or labels at the right hand side of the plot.

I would like the SNP labels to be in the position of the black boxes as per the first two lines on the image (one per vertical line) if possible, but not in boxes just the SNP numbers. Any ideas would be amazing!

test_data_example

SNP        BP_2         PP4    Phenotype   Present 
rs5478100  117.558703    0.5    Diabetes    1
rs6372078  117.563687     0    Diabetes     
rs5866152  117.564875   0.06   Diabetes     1
rs2263839  117.56644    0.05   Diabetes     1
rs6499109  117.568766   0.06   Diabetes     1
rs7863647  117.569046   0.55   Diabetes     1
rs12787678 117.569046   0.2    Diabetes     1
rs5478100  117.558703   0      Cardiac
rs6372078  117.563687   0.4    Cardiac      1
rs5866152  117.56487    0.2    Cardiac      1
rs2263839  117.56644    0.04   Cardiac      1
rs6499109  117.568766   0.19   Cardiac      1
rs7863647  117.569046   0.11   Cardiac      1
rs12787678 117.579457   0.37   Cardiac      1
dot_plot <- ggplot(data, aes(BP_2, Phenotype)) +
  geom_line(aes(group = BP_2)) +
  geom_point(aes(size = Present, colour = Phenotype)) +
  scale_x_continuous(breaks = seq(117.558000, 117.580000, by = 0.002000), position = 'top') +
  theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
                     panel.grid.minor = element_blank(), axis.line.x = element_line(colour = "black"),
                     axis.line.y = element_line(color = "black"))

dot_plot + labs(title="", x="", y = "") +
  theme(legend.position = "none") +
geom_text_repel(aes(label = SNP),
  fontface ="plain", color = "black", size = 3)

enter image description here

0

There are 0 best solutions below