Tuesday, April 16, 2013

RG#70: circular bar plot


library(ggplot2)

#DATA

catg <- c("A", "B", "C", "D", "F", "G")
percent <- c(88, 76, 72, 69, 59, 48)
category <- paste (catg, "-", percent, "%", sep = "")
myd <-data.frame(category,percent)

# converting to factor and applying to 
#levels to set proper order of bars 


myd$category <-factor(myd$category,levels=rev(myd$category))




# plot

plt <- ggplot(myd, aes(x = category, y = percent,fill = category)) + geom_bar(width = 0.85, stat="identity") +    coord_polar(theta = "y") +    xlab("") + ylab("") +
    ylim(c(0,100)) + ggtitle("Graph 1") +    geom_text(data = myd, hjust = 1, size = 3, aes(x = category, y = 0, label = category)) 

plt +  scale_fill_manual(values = c("red1","red4", "green1", "green4", "blue1", "blue4")) + theme_minimal() + theme(legend.position = "none",panel.grid.major = element_blank(),panel.grid.minor = element_blank(),          axis.line = element_blank(),axis.text.y = element_blank(),          axis.text.x = element_blank(), axis.ticks = element_blank())




No comments:

Post a Comment

Note: Only a member of this blog may post a comment.