0

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

holly
  • 41
  • 6
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Nov 09 '22 at 21:59
  • The code you have included is not the code used to create this plot. Where did `dot_plot` come from? Why have you included `heat_map`? Could you perhaps use `dput(data)` to give a reproducible sample of enough data to reproduce your problem (as well as the code to produce your plot)? Thanks – Allan Cameron Nov 09 '22 at 22:05
  • Thank you kindly I have amended the code. Sorry didn't realise the whole thing wasnt there. I have also changed the image to indicate the hopeful position of the labels. Thank you kindly – holly Nov 10 '22 at 09:26

0 Answers0