[R] bar plot stacked

Jim Lemon jim at bitwrit.com.au
Fri Jun 20 00:27:10 CEST 2014


On Thu, 19 Jun 2014 01:42:30 PM message wrote:
> Readers,
> 
> For data set:
> 
> a, 90, 10
> b, 60, 40
> c, ,
> d, , 50
> 
> A plot was attempted:
> 
> dataset<-as.matrix(read.csv("datafile.csv",header=FALSE))
> 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?
> 
Hi message,
Try this:

# this is what you had after reading the data in
testdf<-data.frame(letters[1:4],c(90,60,NA,NA),c(10,40,NA,50))
testmat<-as.matrix(t(testdf[,2:3]))
colnames(testmat)<-testdf[,1]
rownames(testmat)<-NULL
barplot(testmat[,4:1],horiz=TRUE,col=c(NA,"gray"))

Jim



More information about the R-help mailing list