Skip to content

Instantly share code, notes, and snippets.

Created December 24, 2014 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/74ce0e6f9f85b690b589 to your computer and use it in GitHub Desktop.
Save anonymous/74ce0e6f9f85b690b589 to your computer and use it in GitHub Desktop.
PCA_Jan_14<-data.frame(read.table("./PCA_Aug_14.csv", sep=",", fill=T, quote="", stringsAsFactors=FALSE))
scrip<-PCA_Jan_14[-1,]
scrip<-scrip[-1,]
scrip_ordered<-scrip[order(as.numeric(as.character(scrip$V7)), decreasing=T),]
cost<-cbind(scrip$V3, as.numeric(scrip$V11)/(100*as.numeric(scrip$V7)) )
cost<-data.frame(cost)
cost<-cost[!(cost$X2==Inf),]
cost<-aggregate(as.numeric(as.character(cost$X2)), by=list(as.character(cost$X1)), median)
cost_ordered<-cost[order(as.numeric(as.character(cost$x)), decreasing=T), ]
height<-as.numeric(agg$x[1:20]/1E6)
names<-as.character(agg$Group.1[1:20])
names<-ordered(names, levels=rev(names))
cost_height<-as.numeric(cost_ordered$x[1:10])
cost_name<-ordered(as.character(cost_ordered$Group.1[1:10]), levels=rev(cost_ordered$Group.1[1:10]))
cost_type<-scrip$V2[match(cost_name, scrip$V3)]
df<-data.frame(cost_name, cost_height)
mdf<-melt(df)
pdf("top10_prescrip_cost.pdf", width=20, height=7)
ggplot(mdf, aes(cost_name, value, fill=cost_type)) +
geom_bar(stat="identity") +
coord_flip() +
ylab("Cost of one prescription (£'s)") +
xlab("") +
guides(fill=guide_legend(title="British National Formulary Section Name")) +
theme(text = element_text(size=20, colour="black"), axis.text.y = element_text(size=20, colour="black"))
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment