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

use*_*901 6 size fonts r

我在两个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)
Run Code Online (Sandbox Code Playgroud)

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

救命!

mat*_*fee 5

通过帮助阅读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.
Run Code Online (Sandbox Code Playgroud)

因此,只需将您的cex.axisetc参数传递给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)
Run Code Online (Sandbox Code Playgroud)

在R中设置轴属性

(您随后调用从调用axis替换轴的位置plot,因此不使用轴参数plot而是使用轴参数axis).