R-Project Barplot Colors -


i new r, , trying create simple barplot. have been able create barplot correct values, single color bars. if change code ( using table() instead of as.table() ), wrong values, correct colors on graph. how can as.table() accept multiple colors in graph? here altered version of code:

a=30 b=20 c=10 d=15 x=matrix(c(a,b,c,d),ncol=4,byrow=true)    colnames(x)=c("label1","label2","label3","label4")       rownames(x)=c("percentage")       x=as.table(x)       color=c("red","blue","green","orange") barplot(x,main="x",ylab="percent",cex.names=0.75,col=color) 

passing in vector instead of table should trick:

barplot(x[1, ], main="x", ylab="percent", cex.names=0.75, col=color) 

or

barplot(x["percentage", ], main="x",ylab="percent",cex.names=0.75, col=color) 

enter image description here


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -