Creative Commons License R.Muralikrishnan, MPI for Empirical Aesthetics. This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Licence.
# #############################################
# R Script to create circular graphs
#
#
# Author: R.Muralikrishnan
# #############################################

library(ggplot2)

a <- read.table("ranking_singers.txt", header=TRUE)
b <- a[a$Ja=="Self", ]

# We have the x ranging from 2 to 20,
# In a circular plot, the last line will be equal to the first line
# That is, the lines for the first and last x values will coincide
# So the label will be 2/20
# The data for 2 will be represented on the same line as 20...not what we want
# If we started the range at 1, then this is solved, but the label will be 1/20
# To solve this, we just create a dummy line in the input data
# that is exactly equal to the data in 20, but the x value will be 1.
# See Page 203 of R Graphics Cookbook for this trick!
# That's why limits=c(1,20), breaks=seq(2,20)

# We create a dummy x=1 row, that is equal to x=20

bdummy <- b[b$Singer==20,]
bdummy$Singer <- 1 # Replace the index with our dummy 1
bnew <- rbind(b, bdummy)

cairo_pdf("Circular-Plot-1.pdf")

# The limits for y are set from 0, 
# because otherwise it by default starts from 1...and all the ranks 
# that are 1 will be the same point!
ggplot(bnew, aes(x=Singer,y=Rank)) + 
  geom_point(colour="blue") + 
  coord_polar() + 
  scale_x_continuous(limits=c(1,20), breaks=seq(2,20), minor_breaks=seq(2, 20)) + 
  scale_y_continuous(limits=c(0,10), breaks=seq(1,10,by=1)) +  theme_grey(base_size=10, base_family="Verdana")

dev.off()


cairo_pdf("Circular-Plot-2.pdf")

ggplot(bnew, aes(x=Singer,y=Rank)) + 
  geom_line(colour="steelblue") + 
  coord_polar() + 
  scale_x_continuous(limits=c(1,20), breaks=seq(2,20), minor_breaks=seq(2, 20)) + 
  scale_y_continuous(limits=c(0,10), breaks=seq(1,10,by=1)) +  theme_grey(base_size=10, base_family="Verdana")

dev.off()



cairo_pdf("Circular-Plot-3.pdf")

ggplot(bnew, aes(x=Singer,y=Rank)) + 
  geom_segment(aes(xend=Singer,yend=0), colour="steelblue") +
  geom_point(colour="darkorange") + 
  coord_polar() + 
  scale_x_continuous(limits=c(1,20), breaks=seq(2,20), minor_breaks=seq(2, 20)) + 
  scale_y_continuous(limits=c(0,10), breaks=seq(1,10,by=1)) +  theme_grey(base_size=10, base_family="Verdana")


dev.off()