Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change x-axis limits on stratigraphic plots (ie. multi-panel plots)

Tags:

plot

r

lattice

How can I manually adjust the x axis limits for each panel in a stratigraphic plot?

For example, here's Stratiplot from analogue:

library(analogue)
data(V12.122)
Depths <- as.numeric(rownames(V12.122))

(plt <- Stratiplot(Depths ~ O.univ + G.ruber + G.tenel + G.pacR,
                   data = V12.122,  type = c("h","l","g","smooth")))

enter image description here

How could I, for example, change the xlim of G.ruber to c(0.3, 0.9) and G.pacR to c(0, 0.75)?

Or, another possibility, here is strat.plot from rioja:

library(rioja)
library(vegan) ## decorana
data(RLGH)
# remove less abundant taxa
mx <- apply(RLGH$spec, 2, max)
spec <- RLGH$spec[, mx > 3]
depth <- RLGH$depths$Depth
#basic stratigraphic plot
strat.plot(spec, y.rev=TRUE)

enter image description here

How could I, for example, change the xlim of TA004A to c(0, 20)?

I guess that I need to supply something to address the underlying lattice/base plot code, but I'm not sure how to get started with that.

like image 427
Ben Avatar asked Jan 07 '16 00:01

Ben


People also ask

How to change axes limits matlab?

Change Axis LimitsCreate a line plot. Specify the axis limits using the xlim and ylim functions. For 3-D plots, use the zlim function. Pass the functions a two-element vector of the form [min max] .

How do you change the range of the X axis in R?

To change the axis scales on a plot in base R Language, we can use the xlim() and ylim() functions. The xlim() and ylim() functions are convenience functions that set the limit of the x-axis and y-axis respectively.

How do you make a multi panel plot in R?

To make a multi-panel plot, we must change the R graphics parameter mfrow , which stands for “multi-frame rowwise layout”. We can change this parameter with the function par() and the argument mfrow . The value of mfrow is a numeric vector with two elements.


1 Answers

This is a quick part answer by tweaking the limits of the plot object and using the lattice Extra package to resize the panels

# your data
library(analogue)
data(V12.122)
Depths <- as.numeric(rownames(V12.122))

(plt <- Stratiplot(Depths ~ O.univ + G.ruber + G.tenel + G.pacR,
                   data = V12.122,  type = c("h","l","g","smooth")))

# manually change the limits of second panel
# this auto updates ticks and labels
plt$x.limits[[2]] <- c(0.25,0.95) ;

# resize the panels 
latticeExtra::resizePanels(plt, w=c(5,5,5,5))

which gives

enter image description here

This however does not include the small blank space at the start of each segment

like image 199
user20650 Avatar answered Nov 15 '22 05:11

user20650