Concentric Circles like a grid, centered at origin

前端 未结 2 1323
死守一世寂寞
死守一世寂寞 2021-01-05 11:44

I would like to include a sequence of concentric circles as a grid in a plot of points. The goal is to give the viewer an idea of which points in the plot have approximately

相关标签:
2条回答
  • 2021-01-05 11:58

    How about this with ggplot2 and grid:

    require(ggplot2)
    require(grid)
    
    x<-(runif(100)-0.5)*4
    y<-(runif(100)-0.5)*4
    
    circ_rads<-seq(0.25,2,0.25)
    
    qplot(x,y)+
      lapply(circ_rads,FUN=function(x)annotation_custom(circleGrob(gp=gpar(fill="transparent",color="black")),-x,x,-x,x))+
      geom_text(aes(x=0,y=circ_rads+0.1,label=circ_rads)) + coord_fixed(ratio = 1) 
    

    enter image description here

    0 讨论(0)
  • 2021-01-05 11:59

    enter image description here

    set.seed(1)
    xy <- data.frame(x=rnorm(100),y=rnorm(100))
    rmax = sqrt(max(xy$x)^2+max(xy$y)^2)
    theta=seq(from=0,by=.01,to=2*pi)
    ncirc=10
    
    dat.circ = do.call(rbind,
      lapply(seq_len(ncirc),function(n){
      r <- n*rmax/ncirc
      data.frame(x=r*sin(theta),y=r*cos(theta),r=round(r,2))
    }))
    
    rr <- unique(dat.circ$r)
    
    dat.text=data.frame(x=rr*cos(30),y=rr*sin(30),label=rr)
    
    library(ggplot2)
    
    ggplot(xy,aes(x,y))+
       geom_point() +
       geom_path(data=dat.circ,alpha=.2,aes(group=factor(r))) +
       geom_text(data=dat.text,aes(label=rr),vjust=-1)
    
    0 讨论(0)
提交回复
热议问题