How to draw circles inside each other with ggplot2?
I want to draw two circles inside each other with ggplot2.
So far my effort is:
make a fake data and plot it with geom_line(). If I convert this with coord_polar() then I will not be able to see two different circles the one inside each other
library(ggplot2) library(tidyverse) x1=seq(0,6000000,1000) y1=rep(1,length(x1)) y2=rep(2,length(x1)) data=as.data.frame(cbind(x1,y1,y2))
Created on 2021-12-25 by the reprex package (v2.0.1)
# plot the data ggplot(data) + geom_line(aes(x1,y1)) + geom_line(aes(x1,y2)) #coord_polar()
I would avoid the geom_circle option and use the coord_polar option if possible.
The reason is that these two circles have some differences in the x-axis, which I would indicate after drawing the circles.
The code you have with
coord_polar() is correct, just the plot limits need adjusting to see both the circles, e.g.
ggplot(data) + geom_line(aes(x1,y1)) + geom_line(aes(x1,y2)) + coord_polar() + ylim(c(0,NA))
The reason for using
ylim is that this is the direction getting transformed to the radius by the
Answered By – Miff