R: horizontal barcode with Y axis labels next to each bar

I want to create a tablet with 36 groups of 3 horizontal bars. Each group of 3 must have one label.

My code is rather confusing (the first time I use R), so I hope that it will work with some dummy data ...

Anyway:

Transcomp <- matrix(nrow=3, ncol=36) # matrix colnamesbarplot <- colnames(transComp) # should be used as barplot labels barplot <- barplot(transComp, space=c(0,2), legend.text=TRUE, beside=TRUE, horiz=TRUE, density=NA, col=c("red1","red4","green3"), xlab="crimes per 100,000 inhabitants", ylab="districts and years", axes=TRUE ) 

I canโ€™t find a paragraph that allows me to show the column names directly next to the bars (I donโ€™t care if they are to the left or right of the bars) ... Could there be a problem, maybe the number of charts plotted?

Does the answer in add text to the horizontal barcode along the R, y axis at different scales? and the labeling in the bar cabinet () and the Axis Labels for each bar and each group in the histograms with deviated groups do not get me where I want to get ...

Thanks for the help!

+7
source share
1 answer

See the ?barplot arguments.

Some sample data:

 transComp <- matrix(sample(3*36), nrow=3, ncol=36) colnamesbarplot <- as.character(1:36) 

Barplotter:

 barplot(transComp,space=c(0,2),legend.text=TRUE,beside=TRUE,horiz=TRUE, density=NA, col=c("red1","red4","green3"), xlab="crimes per 100,000 inhabitants", ylab="districts and years", axes=TRUE, names.arg=colnamesbarplot, cex.names=0.5, las=1) 

Since you have many columns, you should set cex.names so that the labels are smaller. The las=1 argument rotates labels 90 degrees.

+12
source

All Articles