Skip to main content

Posts

Showing posts from August, 2016

Bar charts in polar coordinates using R package ggplot2

R code providing both an ordinary bar plot and a plot based on polar coordinates.

library(RColorBrewer)
library(ggplot2)
Geography = c(rep('Ukraine in general',3),rep('South-Eastern Ukraine',3),rep('Lower-Southern Ukraine',3),rep('Central Ukraine/Kiev',3),rep('Western Ukraine',3))

Answer = rep(c("Ukraine and Russia must unite into a single state", "Ukraine and Russia must be independent, but friendly states - with open borders, without visas and customs houses","Relations should be the same as with other states - with closed borders, visas and customs houses"))

numbers = c(12.5,68,14.7,25.8,72.2,2,19.4,63.8,10.5,5.4,69.7,20.9,0.7,66.7,24)

df = data.frame(Geography,Answer,numbers)

#install.packages("extrafont")
library(extrafont)

loadfonts(device="win")

ggplot(df, aes(x = Geography)) + geom_bar(aes(weight=numbers, fill = Answer), position = 'fill') + scale_y_continuous("", breaks=NULL) + s…