Home > Enterprise >  ggplot2: How to add padding/gap to segment end points
ggplot2: How to add padding/gap to segment end points

Time:09-07

library(ggplot2)

dfr1 <- data.frame(x=c(1,2),y=c(1,2))
dfr2 <- data.frame(x=1,xend=2,y=1,yend=2)

ggplot() 
  geom_point(data=dfr1,aes(x,y),size=6) 
  geom_segment(data=dfr2,aes(x=xend,y=yend,xend=x,yend=y), color="red",arrow = arrow(length=unit(0.10,"cm"), ends="first", type = "closed")) 
  coord_fixed() 
  theme_minimal()

I would like to add some padding/gap to the start and end of the segment so that they do not overlap the points. Here is a manually edited image to show what I mean:

enter image description here

Created on 2022-09-06 by the enter image description here

  • Related