[R] bar plot stacked

Bart Kastermans kasterma at kasterma.net
Thu Jun 19 16:39:14 CEST 2014


On 19 Jun 2014, at 15:42, message <letter at openmailbox.org> wrote:

> Readers,
> 
> For data set:
> 
> a, 90, 10
> b, 60, 40
> c, ,
> d, , 50
> 
> A plot was attempted:

Wonder who attempted this. :-)

> 
> dataset<-as.matrix(read.csv("datafile.csv",header=FALSE))

Look at your dataset; I’d say it is clearly not what you want.

> barplot<-(dataset,horiz=TRUE)
> 
> A warning message is returned, about NAs introduced by coercion and an undesirable graph. The desired output is something similar to:
> 
> a	---------*
> b	------****
> c
> d	****
> 
> Whereby a legend would be produced to describe '*' and '-'. Any help please?

library(ggplot2)
library(reshape2)
ddd <- read.csv("testdata.csv", header=FALSE)
ggplot(melt(ddd, id.vars="V1"), aes(x=V1, y=value, fill=variable)) + geom_bar(stat="identity") + coord_flip()

Best,
Bart


> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list