# [R] How to add circular text for a graph with concentric circles

Jim Lemon jim at bitwrit.com.au
Wed Jul 25 13:38:36 CEST 2007

```sparandekar at worldbank.org wrote:
> Dear R experts,
>
> I am plotting the population of students who live in a city, and in
> successive circular bands made of the contiguous districts that surround
> the city. This is a stylized figure, where I specify the area of each
> successive circle based on the cumulative population of students. I want
> to compare two sets of concentric circles across different populations -
> such as 'All students' and 'Private students' (those attending private
> school) by using the same colours and the same dimension of the outer
> circle. I have attached the .pdf file with the output, and the R code to
> generate the first set of circles.
>
> I would appreciate any tips about how to rotate the text label that marks
> each concentric circle (except the central circle) to be curved around the
> circle, located in the middle of each band, thus following the circle
> instead of being horizontal, as I have it now.
>
Hi Suhas,
This is kind of rough, being rejigged from an old piece of Postscript
code that I wrote to get text in an arc. You specify the text and
whatever else is needed as in the following example:

midangle=pi/2,stretch=1.1,cex=1,...) {
oldcex<-par("cex")
par(cex=cex)
xwidth<-strwidth(x)*stretch
xvec<-strsplit(x,"")[]
xwidths<-rep(mean(stretch*strwidth(xvec)),length(xvec))
arcpos<-startpos-cumsum(xwidths)
for(i in 1:length(arcpos))
par(cex=oldcex)
}

plot((1:5)
arctext("bendy as a bloody piece of spaghetti",center=c(3,3))