Skip to content
Prev 310229 / 398502 Next

Stacked Barchart as relative share

Hi
On Thu, Nov 8, 2012 at 6:23 AM, Geophagus <fh at retposto.net> wrote:
This is R, so there will be many ways to do it. I don't know what is
considered standard, but I would do

dat <- read.delim("http://r.789695.n4.nabble.com/file/n4648854/example2.csv")
dat[-1] <- apply(dat[-1], 2, function(x) (x/sum(x))*100)


 or does a library generate the complete plot
Here is one way:

library(ggplot2)
library(reshape2)
dat.m <- melt(dat, id.vars="X")
ggplot(dat.m, aes(x=variable, y=value, fill=X)) + geom_bar(stat="identity")

Best,
Ista