首页 文章

在R中旋转轴标签

提问于
浏览
132

在R中,如何使(条形)绘图的y轴标签平行于X轴而不是平行于Y轴?

5 回答

  • 17

    不确定这是不是你的意思,但尝试设置 las=1 . 这是一个例子:

    require(grDevices)
    tN <- table(Ni <- stats::rpois(100, lambda=5))
    r <- barplot(tN, col=rainbow(20), las=1)
    

    output

    这代表了轴标签的风格 . (0 =平行,1 =全部水平,2 =全部垂直于轴,3 =全部垂直)

  • 82

    使用 par(las=1) .

    ?par

    las
    numeric in {0,1,2,3}; the style of axis labels.
    0: always parallel to the axis [default],
    1: always horizontal,
    2: always perpendicular to the axis,
    3: always vertical.
    
  • 149

    正如 Maciej Jończyk 所述,您可能还需要增加利润

    par(las=2)
    par(mar=c(8,8,1,1)) # adjust as needed
    plot(...)
    
  • 8

    您需要使用theme()函数,如下所示将x轴标签旋转60度:

    ggplot(...)+...+ theme(axis.text.x = element_text(angle=60, hjust=1))
    
  • 0

    首先,为图表创建数据

    H <- c(1.964138757, 1.729143013,    1.713273714,    1.706771799,    1.67977205)
    M <- c("SP105", "SP30", "SP244", "SP31",    "SP147")
    

    其次,给出图表文件的名称

    png(file = "Bargraph.jpeg", width = 500, height = 300)
    

    第三,绘制条形图

    barplot(H,names.arg=M,ylab="Degree ", col= rainbow(5), las=2, border = 0, cex.lab=1, cex.axis=1, font=1,col.axis="black")
    title(xlab="Service Providers", line=4, cex.lab=1)
    

    最后,保存文件

    dev.off()
    

    输出:

    enter image description here

相关问题