[R] plot level, velocity, acceleration with one x axis
Viechtbauer, Wolfgang (NP)
wo||g@ng@v|echtb@uer @end|ng |rom m@@@tr|chtun|ver@|ty@n|
Wed May 31 21:12:28 CEST 2023
How about using the same 'mar' for all plots, but adding an outer margin?
DAX <- EuStockMarkets[, 'DAX']
DAX. <- cbind(DAX, diff(log(DAX)), diff(diff(log(DAX))))
colnames(DAX.) <- c("DAX", 'vel (%)', 'accel (%)')
head(DAX.)
par(mfrow=c(3,1), mar=c(1,4.5,0,2), oma=c(3,0,1,0))
plot(DAX.[, 1], log='y', ylab='DAX', axes=FALSE)
axis(2)
box(col='grey')
plot(DAX.[, 2], ylab='vel (%)', axes=FALSE)
axis(2)
box(col='grey')
plot(DAX.[, 3], ylab='accel (%)', axes=FALSE)
axis(2)
box(col='grey')
axis(1)
Best,
Wolfgang
>-----Original Message-----
>From: R-help [mailto:r-help-bounces using r-project.org] On Behalf Of Spencer Graves
>Sent: Wednesday, 31 May, 2023 17:45
>To: Eric Berger
>Cc: r-help
>Subject: Re: [R] plot level, velocity, acceleration with one x axis
>
>On 5/31/23 9:20 AM, Eric Berger wrote:
>> I sent you an updated response to deal with the redundant copies of the x-axis.
>> Re-sending.
>>
>par(mfrow=c(3,1))
>plot(DAX.[, 1], log='y', ylab='DAX', xaxt="n")
>plot(DAX.[, 2], ylab='vel (%)', xaxt="n")
>plot(DAX.[, 3], ylab='accel (%)')
>
> I got that. The primary problem with that is that most of the
>vertical space is reserved for axis labels, whether they are printed or
>not. If I squeeze the vertical dimension of the plot, I get, "figure
>margins too large". To control that, I need to set "mar" separately for
>each panel, and then the plot regions for each are not the same size.
>Using the "layout" function instead of "mfrow" is better, but I don't
>see now to make that work consistently without fixing the aspect ratio.
>There may be a way in the tidyverse, but I haven't found it yet. The
>only solution I've found so far that makes sense to me is to modify the
>code for plot.ts to accept a vector for the log argument, with the
>constraint that length(lot) = either 1 or ncol(x) and returning
>invisibly an object that would make it feasible for a user to call
>axis(2, ...) once for each vertical axis to handle cases where someone
>wanted to a vertical scale different from linear and log. I'd want to
>make sure that lines.ts also works with this, because I want to add fits
>and predictions.
>
> Comments?
> Thanks,
> Spencer Graves
>
>** With either of the following plots, if I adjust the aspect ratio by
>enlarging or reducing the vertical dimension of the plot, the relative
>sizes of the plot regions change.
>
>DAX <- EuStockMarkets[, 'DAX']
>DAX. <- cbind(DAX, diff(log(DAX)), diff(diff(log(DAX))))
>colnames(DAX.) <- c("DAX", 'vel (%)', 'accel (%)')
>head(DAX.)
>
>plot(DAX., log='xy')
>
>op <- par(mfrow=c(3,1), mar=c(0, 4.1, 4.1, 2.1))
>plot(DAX.[, 1], log='y', ylab='DAX', axes=FALSE)
>axis(2)
>box(col='grey')
>par(mar=c(0, 4.1, 0, 2.1))
>plot(DAX.[, 2], ylab='vel (%)', axes=FALSE)
>axis(2)
>box(col='grey')
>par(mar=c(5.1, 4.1, 0, 2.1))
>plot(DAX.[, 3], ylab='accel (%)', axes=FALSE)
>axis(2)
>box(col='grey')
>axis(1)
>par(op)
More information about the R-help
mailing list