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

Hi everyone,
It's been a long time since I post last time. For your help, I make some progress in learning R. I meet a new problem when drawing. How to turn the auxiliary line inside a circle into dashed line?At the same time, is it possible to use the function to count the number of points in the circle?
Thank you for your effort and time on this problem in advance.

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
)
``` r
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")
p
p1<-p+annotate("segment", x = 13.6, xend = 33.6, y = 19.8, yend = 19.8,size = 1,color='blue')+annotate("segment", x = 23.6, xend = 23.6, y = 9.8, yend = 29.8,size = 1,color='blue')
p1

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

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

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.