[英]How to modify the size of the x axis text in a twoord plot from the plotrix package?
I would like to make a twoord plot where I would like to decrease the size of the text on the x axis. 我想制作一个双向图,我想减小x轴上文本的大小。 So I am looking for the alternative to cex.axis. 所以我正在寻找cex.axis的替代品。 I tried using cexlab.axis but it changes the y axis values.I also tried to suppres the x axis altogether and then customise the x axis by specifying 我尝试使用cexlab.axis,但它改变了y轴值。我也尝试完全抑制x轴,然后通过指定自定义x轴
twoord.plot(lx=1:96, ly=mean_aod, rx=1:96, ry=tot_FCH,type=c("b","bar"),xaxt="n")
axis(1, at = seq(1, 96, by = 1),srt=45, cex.axis=0.5)
But this doesn't get rid of the default labels plotted by twoord.plot. 但这并没有摆脱由twoord.plot绘制的默认标签。 Basically I want the x axis labels to be from 1 to 96 at each of the 96 tick marks. 基本上我希望x轴标签在96个刻度标记的每一个上都是1到96。 The closest I have got to this is by specifying a variable month that runs from 1 to 96 and then running the code below. 我最接近的是指定一个从1到96运行的变量月份,然后运行下面的代码。
twoord.plot(lx=1:96, ly=mean_aod, rx=1:96, ry=tot_FCH,type=c("b","bar"), xticklab=month)
But the size of each label is too big and not all the labels are displayed. 但是每个标签的尺寸太大而且并非所有标签都显示出来。 How can I rectify this? 我怎么能纠正这个? Many thanks in advance. 提前谢谢了。
Looking at page(twoord.plot)
we see that in twoord.plot
when plot
is called, argument axes
is -already- set to FALSE
and axes are built by calling axis
. 纵观page(twoord.plot)
我们看到,在twoord.plot
当plot
被调用,参数axes
是-already-设置为FALSE
和轴通过调用内置axis
。 So, xaxt
won't have any effect. 所以, xaxt
不会有任何影响。
The thing is, though, that in the code is written: axis(1, ... **cex** = axilsab.cex
. But setting cex
in axis
won't have the desired effect; cex.axis
should be used instead. For axes 2 and 4, though, axilslab.cex
argument is used by calling mtext
. Eg mtext(axat, 2... cex = axislab.cex
; here cex
(inside mtext
) has the desired effect. 但是,在代码中写的是: axis(1, ... **cex** = axilsab.cex
。但是在axis
设置cex
不会产生预期的效果;应该使用cex.axis
代替但是,对于轴2和4,通过调用mtext
来使用axilslab.cex
参数。例如mtext(axat, 2... cex = axislab.cex
;这里cex
(在mtext
)具有所需的效果。
Concluding, you can write a function twoord.plot2
where you change the cex
argument to cex.axis
when calling axis(1...
. And then run your code by calling twoord.plot2
. Ie axis(1,... **cex.axis** = axislab.cex)
. 最后,您可以编写一个函数twoord.plot2
,你改变cex
参数cex.axis
调用时axis(1...
。然后通过调用运行代码twoord.plot2
。即axis(1,... **cex.axis** = axislab.cex)
。
EDIT 编辑
I will add a x_axislab.cex
argument in the original twoord.plot
in order to change only the size of x-axis' tickmarks: 我将在原始的twoord.plot
中添加一个x_axislab.cex
参数,以便仅更改x轴'标记的大小:
Copy-paste everything from page(twoord.plot)
in a text editor and name it twoord.plot2
. 从文本编辑器page(twoord.plot)
中的所有内容复制粘贴并命名为twoord.plot2
。 Then add an extra argument and change the body of the function: 然后添加一个额外的参数并更改函数体:
twoord.plot2 <- #function (lx, ly, rx, ry, data = NULL, xlim = NULL, lylim = NULL,
#rylim = NULL, mar = c(5, 4, 4, 4), lcol = 1, rcol = 2, xlab = "",
#ylab = "", rylab = "", lpch = 1, rpch = 2, type = "b", xtickpos = NULL,
#xticklab = NULL, halfwidth = 0.4, axislab.cex = 1,
**x_axislab.cex = 1**, # do.first = NULL,
# ...) #add argument `x_axislab.cex = 1` in the arguments of the original `twoord.plot`
#{
# if (!is.null(data)) {
# ly <- unlist(data[ly])
#...everything else...
#if (is.null(xticklab))
axis(1, **cex.axis = x_axislab.cex**) #change here. it was **cex = axislab.cex**
# else {
#if (is.null(xtickpos))
#xtickpos <- 1:length(xticklab)
# if (is.null(xticklab))
# xticklab <- xtickpos
axis(1, at = xtickpos, labels = xticklab, **cex.axis = x_axislab.cex**) #change here. it was **cex = axislab.cex**
#.....everything else...
Then copy-paste your function in R
and run something like: 然后在R
复制粘贴您的函数并运行如下:
twoord.plot2(...other arguments..., x_axislab.cex = 0.8)
to plot your data and change the size of x-axis' tickmarks. 绘制数据并更改x轴'刻度线的大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.