Skip to content

Commit

Permalink
better plot margins
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasjclark committed Aug 8, 2023
1 parent 1a146a6 commit 3af0bc4
Show file tree
Hide file tree
Showing 39 changed files with 237 additions and 272 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Imports:
posterior (>= 1.0.0),
loo (>= 2.3.1),
parallel,
collapse,
pbapply,
tweedie,
MASS,
Expand Down
8 changes: 5 additions & 3 deletions R/as.data.frame.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ as.data.frame.mvgam = function(x,

# Get a string of all possible variables to extract
all_vars <- variables(x)
all_orig_vars <- unique(unlist(purrr::map(all_vars, 'orig_name')))
all_alias_vars <- unique(unlist(purrr::map(all_vars, 'alias')))
all_orig_vars <- unlist(purrr::map(all_vars, 'orig_name'))
all_alias_vars <- unlist(purrr::map(all_vars, 'alias'))

all_orig_walias <- all_orig_vars[!is.na(all_alias_vars)]
all_alias_vars <- all_alias_vars[!is.na(all_alias_vars)]

# All possible var sets to extract
Expand Down Expand Up @@ -191,7 +193,7 @@ as.data.frame.mvgam = function(x,
names_to_use[[i]] <- NA
} else {
if(any(all_alias_vars == variable[i])){
vars_to_extract[[i]] <- unname(unlist(purrr::map(all_vars, 'orig_name'))[
vars_to_extract[[i]] <- unname(all_orig_walias[
which(all_alias_vars == variable[i])])
names_to_use[[i]] <- variable[i]
} else {
Expand Down
2 changes: 1 addition & 1 deletion R/globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ utils::globalVariables(c("y", "year", "smooth_vals", "smooth_num",
"mod_call", "particles", "obs", "mgcv_model",
"param_name", "outcome", "mgcv_plottable",
"term", "data_test", "object", "row_num", "trends_test",
"trend"))
"trend", "trend_series", "trend_y", "."))
10 changes: 7 additions & 3 deletions R/plot.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ plot.mvgam = function(x, type = 'residuals',
n_plots <- n_smooths
if (n_plots==0) stop("No suitable terms to plot - plot.mvgam() only handles smooths of 2 or fewer dimensions.")
pages <- 1
.pardefault <- par(no.readonly=T)
par(.pardefault)

if (n_plots > 4) pages <- 2
if (n_plots > 8) pages <- 3
Expand All @@ -179,7 +177,13 @@ plot.mvgam = function(x, type = 'residuals',
if (c<1) r <- c <- 1
if (c*r < ppp) c <- c + 1
if (c*r < ppp) r <- r + 1
oldpar<-par(mfrow=c(r,c))

.pardefault <- par(no.readonly=T)
par(.pardefault)
oldpar<-par(mfrow=c(r,c),
mar=c(2.5, 2.3, 2, 2),
oma = c(1, 1, 0, 0),
mgp = c(1.5, 0.5, 0))

} else { ppp<-1;oldpar<-par()}

Expand Down
15 changes: 12 additions & 3 deletions R/plot_mvgam_factors.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,20 @@ plot_mvgam_factors = function(object, plot = TRUE){
.pardefault <- par(no.readonly=T)
par(.pardefault)
if(object$n_lv <= 2){
par(mfrow = c(1, 2))
par(mfrow = c(1, 2),
mar=c(2.5, 2.3, 2, 2),
oma = c(1, 1, 0, 0),
mgp = c(1.5, 0.5, 0))
} else if(object$n_lv <= 4){
par(mfrow = c(2, 2))
par(mfrow = c(2, 2),
mar=c(2.5, 2.3, 2, 2),
oma = c(1, 1, 0, 0),
mgp = c(1.5, 0.5, 0))
} else {
par(mfrow = c(3, 2))
par(mfrow = c(3, 2),
mar=c(2.5, 2.3, 2, 2),
oma = c(1, 1, 0, 0),
mgp = c(1.5, 0.5, 0))
}
}

Expand Down
10 changes: 8 additions & 2 deletions R/plot_mvgam_pterms.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,17 @@ if(length(pterms) > 0){
}

if(length(pterms) == 2){
par(mfrow = c(2, 1))
par(mfrow = c(2, 1),
mar=c(2.5, 2.3, 2, 2),
oma = c(1, 1, 0, 0),
mgp = c(1.5, 0.5, 0))
}

if(length(pterms) %in% c(3, 4)){
par(mfrow = c(2, 2))
par(mfrow = c(2, 2),
mar=c(2.5, 2.3, 2, 2),
oma = c(1, 1, 0, 0),
mgp = c(1.5, 0.5, 0))
}

for(i in 1:length(pterms)){
Expand Down
Loading

0 comments on commit 3af0bc4

Please sign in to comment.