How to turn the auxiliary line inside a circle into dashed line?

Hi,

The method is exactly the same as you did for the circle, just add linetype = "dashed" the annotate function like this

library(ggplot2)

data1<-data.frame(x=c(26.4,28.4,29.7,24.9,25.1,23.6,21.6,30),
                  y=c(17.1,16.9,17.8,18.5,19.5,19.8,16.8,30),
                  z=c(17.8,13.5,20.9,20.8,15,10.2,9.3,9.9))
library(ggplot2)
library(ggforce)
circles<-data.frame(
  x0=23.6,
  y0=19.8,
  r=10
)

p<-ggplot(data = data1)+
  geom_point(aes(x=x,y=y,size=z),color="black",shape=1)+
  geom_circle(aes(x0=x0,y0=y0,r=r),
              data = circles,
              color = "red",
              alpha=0.05,
              linetype="dashed")

p1<-p+annotate("segment", x = 13.6, xend = 33.6, y = 19.8, 
               yend = 19.8,linewidth= 1,color='blue', linetype = "dashed")+
  annotate("segment", x = 23.6, xend = 23.6, y = 9.8, 
           yend = 29.8,linewidth= 1,color='blue', linetype = "dashed")
p1

Created on 2023-02-09 with reprex v2.0.2

If you like to see the names / codes for other line types, check this link

Hope this helps,
PJ

1 Like