Created
February 21, 2018 11:42
-
-
Save mwalzer/aebf9b2cacac7a2b2af78b967e49b9bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
# ggpie: draws a pie chart. | |
# give it: | |
# * `dat`: your dataframe | |
# * `by` {character}: the name of the fill column (factor) | |
# * `totals` {character}: the name of the column that tracks | |
# the time spent per level of `by` (percentages work too). | |
# returns: a plot object. | |
#credit http://mathematicalcoffee.blogspot.co.uk/2014/06/ggpie-pie-graphs-in-ggplot2.html | |
ggpie <- function (dat, by, totals) { | |
ggplot(dat, aes_string(x=factor(1), y=totals, fill=by)) + | |
geom_bar(stat='identity', color='black') + | |
guides(fill=guide_legend(override.aes=list(colour=NA))) + # removes black borders from legend | |
coord_polar(theta='y') + | |
theme(axis.ticks=element_blank(), | |
axis.text.y=element_blank(), | |
axis.text.x=element_text(colour='black'), | |
axis.title=element_blank()) + | |
scale_y_continuous(breaks=cumsum(dat[[totals]]) - dat[[totals]] / 2, labels=dat[[by]]) | |
} | |
clusterdiskusage_icgconly <- read.csv("/tmp/clusterdiskusage_icgconly.csv", header=FALSE) | |
View(clusterdiskusage_icgconly) | |
#V1 is GB size, V2 project name | |
library(grid) # for `unit` | |
library(dplyr) | |
c <- arrange(clusterdiskusage_icgconly, desc(V1)) | |
ggpie(c, by='V2', totals='V1') + | |
ggtitle("Clusterstorage use.") + | |
theme(axis.ticks.margin=unit(0,"lines"), | |
plot.margin=rep(unit(0, "lines"),4)) | |
#Does not work that nice with polar coord labels, consider | |
#http://www.sthda.com/english/wiki/ggplot2-pie-chart-quick-start-guide-r-software-and-data-visualization |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment