R: horizontal barplot with y-axis-labels next to every bar

Pik*_*tja 7 plot label axis r

I want to design a barplot with 36 groups of 3 horizontal bars. Next to each group of 3, there should be one label.

我的代码很混乱(我第一次使用R),所以我希望它能用于一些虚拟数据......

无论如何:

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
            )
Run Code Online (Sandbox Code Playgroud)

我找不到允许我直接在条形图旁边显示列名称的参数(我不在乎它们是在条形图的左侧还是右侧)...问题可能是数字酒吧绘制?

在answeres 添加文本中的R水平barplot,y轴在不同尺度?在barplot()标记轴标签为每个栏和各组条形图与回避团体不要误会我,我想获得...

感谢您的任何帮助!

use*_*275 14

看看?barplot论点names.arg.

一些示例数据:

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

条形图:

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)
Run Code Online (Sandbox Code Playgroud)

由于您要绘制许多列,因此应将其设置cex.names为使标注更小.参数las=1将标签旋转90度.