R:如何旋转副 Y Axis 的标签?? {根据}

标签 r plot label axis2 axis-labels

我已经创建了第二个 Y Axis ,并且还使用 mtext 在此处放置了一个标签。但是,我不知道如何旋转我的次要 Y 标签以面对绘图 - 就像我的红色 Y2 标签

我的虚拟数据,取自:http://robjhyndman.com/hyndsight/r-graph-with-two-y-axes/

x <- 1:5
y1 <- rnorm(5)
y2 <- rnorm(5,20)
par(mar=c(5,4,4,5)+.1)
plot(x,y1,type="l",col="red")
par(new=TRUE)
plot(x, y2,,type="l",col="blue",xaxt="n",yaxt="n",xlab="",ylab="")
axis(4)
mtext("y2",side=4,line=3)
legend("topleft",col=c("red","blue"),lty=1,legend=c("y1","y2"))

结果:

enter image description here

我试过 srt = ...las = ...,它们都不起作用。

我不一定需要使用mtext,请问还有其他简单的解决方案吗?

谢谢!

最佳答案

使用text代替mtext:

set.seed(1)
x <- 1:5
y1 <- rnorm(5)
y2 <- rnorm(5,20)
par(mar=c(5,4,4,5)+.1)
plot(x,y1,type="l",col="red")
par(new=TRUE)
plot(x, y2,,type="l",col="blue",xaxt="n",yaxt="n",xlab="",ylab="")
axis(4)
text(par("usr")[2]*1.11,mean(par("usr")[3:4]), "y2", srt = -90, xpd = TRUE, pos = 4)
legend("topleft",col=c("red","blue"),lty=1,legend=c("y1","y2"))

( via )

enter image description here

关于R:如何旋转副 Y Axis 的标签?? {根据},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36459314/

相关文章:

r - 使用 RStudio Connection Pane 连接 PostgreSQL 数据库

r - 使用 RSQLite 时,数据库中的日期数据会发生什么?

r - 如何从 case_when() 返回多个值或一个小标题?

c - 内联汇编 --> 错误 : internal_relocation (type: OFFSET_IMM) not fixed up

r - 将向量解包到列表中,向量的每个元素作为列表中的单独元素

r - 如果矩阵而不是数据框,则 R 绘图中的标记点不打印

matlab - 独立于 x 值更改 x Axis 标签?

r - r 中决策树中的叠加直方图

ruby-on-rails - 使用 block 级标签和输入的 Twitter Bootstrap

c# - 标签图像模式拉伸(stretch)