简体   繁体   English

45 度角的 x 轴标签相互堆叠

[英]x axis labels at 45 degrees are stacked on top of each other

I have been attempting to tilt my x axis labels to 45 degrees.我一直在尝试将 x 轴标签倾斜 45 度。 Currently when I run the program, all the titles are stacked on top of each other at each axis.目前,当我运行该程序时,所有标题都在每个轴上堆叠在一起。

I expected my code to display my x axis labels at a 45 degree angle, one label per tick, not every label on every tick.我希望我的代码以 45 度角显示我的 x 轴标签,每个刻度一个 label,而不是每个刻度上的每个 label。

boxplot(x ~ y, data=df, pars=list(xaxt="n")  ## boxplot with x axis labels eliminated
axis(1, at=seq(1, 15, by=1), labels=FALSE)  ## x axis ticks with no labels
text(seq(1, 15, by=1), par("usr")[3] - 1, labels=df$name, srt=45, pos=1, xpd=TRUE)  ## x axis labels at 45 degrees, but they are stacked on top of each other.

Do I need to relabel my dataset, specifically in the df$name?我是否需要重新标记我的数据集,特别是在 df$name 中? Does the labels=df$name have too many names, which stack on top of each other? labels=df$name是否有太多的名称,它们相互堆叠?

This code is from this source: https://stats.oarc.ucla.edu/r/faq/how-can-i-change-the-angle-of-the-value-labels-on-my-axes/此代码来自以下来源: https://stats.oarc.ucla.edu/r/faq/how-can-i-change-the-angle-of-the-value-labels-on-my-axes/

You just want the unique elements of the names.您只需要名称的unique元素。

Example, using builtin InsectSprays dataset:例如,使用内置InsectSprays数据集:

boxplot(count ~ spray, data=InsectSprays, xaxt="n")
sq <- seq_along(unique(InsectSprays$spray))
axis(1, at=sq, labels=FALSE) 
text(sq, par("usr")[3] - 1.5, labels=unique(InsectSprays$spray), 
     srt=45, pos=1, xpd=TRUE)

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM