首页 文章

R stat定义x上的标签角度,用于为索引值分配标签文本

提问于
浏览
1

我正在完成我的脚本,但我无法为x标签设置角度 . 我想将它用于特定索引位置的数据:

INPUT:

xlabel < - (0,100,200,250,336)xlabel.popis < - (“TATA”,“MAMA”,“OND”,“KOKO”,“LOLO”)

输出:将xlabel.popis绘制在x轴上的特定xlabel位置上(x轴是索引线(0..500)),xlabel.popis将具有垂直旋转 .

我试过了:

plot(read.table(files2[i],header=F,sep="\t")$V7,main=file_bez2[i], axes=FALSE)
xlabel <- (0,100,200,250,336)
xlabel.popis <- ("TATA","MAMA","OND","KOKO","LOLO")
axis(1, at=seq_along(xlabel),labels=as.character(xlabel.popis, las=2, cex.label=90))

或者我没试过轴但是 mtext(as.character(xlabel.popis),side=1,line=1.1,at=xlabel,srt=90) 什么都没有用,你能不能帮助我,对于我来说,轴定义会更好 . 而par()定义也不行 . 非常感谢

1 回答

  • 1

    我相信你需要在调用 axis 之后用 text 函数添加标签 .

    示例:

    xlabel <- c(0,100,200,250,336)
    xlabel.popis <- c("TATA","MAMA","OND","KOKO","LOLO")
    
    plot(range(xlabel), c(1,1), t="l", xaxt="n", xlab="")
    axis(1, at=xlabel, labels=FALSE)
    text(x=xlabel, y=par()$usr[3]-0.1*(par()$usr[4]-par()$usr[3]),
    labels=xlabel.popis, srt=45, adj=1, xpd=TRUE)
    

    enter image description here

    如果您只想旋转90°,请考虑 las 参数:

    plot(range(xlabel), c(1,1), t="l", xaxt="n", xlab="")
    axis(1, at=xlabel, labels=xlabel.popis, las=2)
    

    enter image description here

相关问题