[R] Different stack barplots - same color legends

P. Roberto Bakker robertob@kker @ending from gm@il@com
Mon Oct 22 16:03:54 CEST 2018


Hi,

I want to make barplots from different questions (columns) in one
data.frame.
Each question has the same 5 likert items.
Now the problem: in some questions all items are answered; in other less.
>From the syntax below I get nice stack barplots - *but the legend colors do
not* refer to the same likert-item, which I understand - the colors go in
sequence along the table.
Question: how can I write a syntax that each likert-item has the same
legend color?
Thank you in advance,

Roberto

SYNTAX:
counts19 <- table(teamq[,19])
counts20 <- table(teamq[,20])
barplot(as.matrix(counts19), horiz = T,
        col=c("yellow","sandybrown","orange", "darkolivegreen","green"),
legend=T)
barplot(as.matrix(counts20), horiz = T,
        col=c("yellow","sandybrown","orange", "darkolivegreen","green"),
legend=T)

	[[alternative HTML version deleted]]



More information about the R-help mailing list