簡體   English   中英

45 度角的 x 軸標簽相互堆疊

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

我一直在嘗試將 x 軸標簽傾斜 45 度。 目前,當我運行該程序時,所有標題都在每個軸上堆疊在一起。

我希望我的代碼以 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.

我是否需要重新標記我的數據集,特別是在 df$name 中? labels=df$name是否有太多的名稱,它們相互堆疊?

此代碼來自以下來源: https://stats.oarc.ucla.edu/r/faq/how-can-i-change-the-angle-of-the-value-labels-on-my-axes/

您只需要名稱的unique元素。

例如,使用內置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