gpt4 book ai didi

R - 如何更改已移动到图表顶部的两个 x 轴的字体样式和大小?

转载 作者:行者123 更新时间:2023-12-04 12:34:08 24 4
gpt4 key购买 nike

我在更改两个 x 轴上的字体样式和大小时遇到​​了麻烦,这两个 x 轴都已移至图表顶部。

到目前为止,这是我的代码:

x1<-Temperature
x2<-Salinity

y<-Depth
par(mar=c(4, 4, 8, 4))

plot(x2,y, type="l",col="darkgrey",ylim=rev(range(0,300)),las=2,xlim=(range(32.5,34.5)),xaxt='n',xlab='',font.axis=2,lwd=3,ylab="Depth [m]",font=2,font.lab=2,cex.lab=1.3,cex.axis=1.2)
axis(side=3, line=4)
par(new=TRUE)
plot(x1,y, type="l",col="black",ylim=rev(range(0,300)),las=2,xaxt='n',xlab='',lwd=3,ylab='Depth [m]',font=2,font.lab=2,cex.lab=1.3,cex.axis=1.2)
axis(side=3, line=0)
par(new=TRUE)

这成功地改变了我的 y 轴,但保持我的 x 轴不变。

帮助!

最佳答案

阅读 axis 的帮助, ?axis ,查看 ... 的文档参数:

 ...: other graphical parameters may also be passed as arguments to
this function, particularly, ‘cex.axis’, ‘col.axis’ and
‘font.axis’ for axis annotation, ‘mgp’ and ‘xaxp’ or ‘yaxp’
for positioning, ‘tck’ or ‘tcl’ for tick mark length and
direction, ‘las’ for vertical/horizontal label orientation,
or ‘fg’ instead of ‘col’, and ‘xpd’ for clipping. See ‘par’
on these.

所以只需传递你的 cex.axis等参数到 axis像您一样调用 plot .这是 可重现的示例 (注意我是如何组成数据的,即使数据不现实,至少它使示例可重现并且仍然解决了您的问题):
x1 <- runif(10)
x2 <- runif(10) * 2 + 32.5
y <- runif(10) * 300

par(mar=c(4, 4, 8, 4))
plot(x2,y, type="l",col="darkgrey",ylim=rev(range(0,300)),las=2,xlim=(range(32.5,34.5)),xaxt='n',xlab='',font.axis=2,lwd=3,ylab="Depth [m]",font=2,font.lab=2,cex.lab=1.3,cex.axis=1.2)

# added in various font/axis labels as in above
axis(side=3, line=4,font.axis=2,font.lab=2,cex.lab=1.3,cex.axis=1.2)

par(new=TRUE)
plot(x1,y, type="l",col="black",ylim=rev(range(0,300)),las=2,xaxt='n',xlab='',lwd=3,ylab='Depth [m]',font=2,font.lab=2,cex.lab=1.3,cex.axis=1.2)
axis(side=3, line=0,font.axis=2,font.lab=2,cex.lab=1.3,cex.axis=1.2)

setting axis properties in R

(您随后对 axis 的调用从 plot 调用中替换轴,因此不使用 plot 中的轴参数,而是使用 axis 中的轴参数)。

关于R - 如何更改已移动到图表顶部的两个 x 轴的字体样式和大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13224320/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com