[英]Rotate axis label upside down in R base plot
在基礎R繪圖中我需要一些關於軸標簽的幫助,提前感謝任何指導!
在R
base plot()
我想將我的axis(3, ...)
標簽旋轉到-90度以獲得以下輸出:
(請注意,我已將圖片旋轉到R外)
我正在使用labcurve
進行曲線注釋,奇怪的是,對於我的數據,如果應用於-90度旋轉圖形,注釋結果在視覺上會更好。 運行labcurve
我可以將生成的R生成的PDF在LaTeX中旋轉90度。
我知道,這是由管轄las
在選項par
有以下選項:
0: always parallel to the axis [default],
1: always horizontal,
2: always perpendicular to the axis,
3: always vertical.
但是,這四個選項僅覆蓋0度和90度兩個角度,如下所示:
plot(x=c(0,10), y=c(0,1), type='n', xlab='',ylab='', axes=FALSE)
lines(x=c(0,7,7,10), y=c(0,0.33,0.67,1))
axis(2, at=c(0,1), labels=c('',''), las=2)
xlabels <- c('0','10')
axis(3, at=c(0,10), labels=xlabels, las=0)
要么
axis(3, at=c(0,10), labels=xlabels, las=1)
axis(3, at=c(0,10), labels=xlabels, las=2)
要么
axis(3, at=c(0,10), labels=xlabels, las=3)
人們可以想到str
但根據文件:
請注意,通過參數srt到par的字符串/字符旋轉不會影響軸標簽。
再次感謝!
R FAQ 7.27中描述了創建旋轉軸標簽的一般步驟。 這是一個可以滿足您需求的修改示例。
# some toy data
x <- c(0, 2, 6, 10)
y <- sample(1:4)
# Increase top margin to make room for rotated labels
par(mar = c(5, 4, 7, 2) + 0.1)
# Create plot without axis or labels
plot(x, y, type = "l", axes = FALSE, xlab = "", ylab = "")
# positions for tick marks
atx <- range(x)
aty <- range(y)
# x axis without labels
axis(side = 3, at = atx, labels = FALSE)
# y axis without labels
axis(side = 2, at = aty, labels = FALSE)
# add -90 rotated x axis labels
text(x = atx, y = par("usr")[4] + 0.25, srt = -90, adj = 1,
labels = atx, xpd = TRUE)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.