You need to sign in or sign up before continuing.
Newer
Older
# Variable width column chart, based on https://learnr.wordpress.com/2009/03/29/ggplot2-variable-width-column-chart/
library(tidyverse) # open package tidyverse (if you don't have it, run install.packages('tidyverse') in the console)
# Creation of example data
df <- data.frame(mitigation=c('reduced feed losses', 'nr lactations',
'feed ads','endogenous'),
width=c(2,5,12,3), height=c(20,30,70,120)
)
df$w <- cumsum(df$width) # Calculating cumulative sum of the widths
df$wm <- df$w - df$width
df$wt <- with(df, wm+(w-wm)/2)
p <- ggplot(df, aes(ymin=0))
p1 <- p + geom_rect(aes(xmin=wm, xmax=w, ymax=height, fill=mitigation))
p2 <- p1 + geom_text(aes(x=wt, y=height*0.5, label=mitigation), size = 4)
p2+theme_bw()+
ylab('MAC')+
xlab('Reduction')+
guides(fill=guide_legend(title='Mitigation measures'))