Skip to content

Commit

Permalink
Merge pull request #865 from mmitsuyo/0719
Browse files Browse the repository at this point in the history
fix xlim in plot_residual_vpa
  • Loading branch information
mmitsuyo authored Jul 19, 2024
2 parents cc2ca10 + a178791 commit 97106f8
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions R/diagnostics_vpa.R
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ plot_residual_vpa2 <- function(res, index_name = NULL, plot_smooth = FALSE, plot
facet_wrap(~Index_Label, scale = if(plot_scale) "free" else "fixed",axes="all_x")+
geom_hline(yintercept = 0, linewidth = 1)+
xlab("Year") +
xlim(xlim_year) +
#xlim(xlim_year) +
ylab("log(Residual)") +
theme_SH(base_size = 14)+
geom_label(data = rho_data,
Expand All @@ -755,15 +755,15 @@ plot_residual_vpa2 <- function(res, index_name = NULL, plot_smooth = FALSE, plot
", rho=", round(ar1,2), signif)),
vjust="inward", hjust="inward")+
guides(x=guide_axis(minor.ticks = TRUE))+
scale_x_continuous(breaks=scales::breaks_pretty(),minor_breaks=scales::breaks_width(1))
scale_x_continuous(limits=xlim_year,breaks=scales::breaks_pretty(),minor_breaks=scales::breaks_width(1))
g1_sd <- ggplot(d_tidy) +
geom_ribbon(aes(x = year, ymin = -qnorm(0.025), ymax = qnorm(0.025)), alpha=0.05)+
geom_ribbon(aes(x = year, ymin = -qnorm(0.1), ymax = qnorm(0.1)), alpha=0.1)+
geom_point(aes(x=year, y=sd.resid, colour = Index_Label), size = 2) +
facet_wrap(~Index_Label, scale = if(plot_scale) "fixed" else "free",axes="all_x")+
geom_hline(yintercept = 0, linewidth = 1)+
xlab("Year") +
xlim(xlim_year) +
#xlim(xlim_year) +
ylab("log(Residual)") +
theme_SH(base_size = 14)+
geom_label(data = rho_data,
Expand All @@ -772,14 +772,14 @@ plot_residual_vpa2 <- function(res, index_name = NULL, plot_smooth = FALSE, plot
", rho=", round(ar1,2), signif)),
vjust="inward", hjust="inward")+
guides(x=guide_axis(minor.ticks = TRUE))+
scale_x_continuous(breaks=scales::breaks_pretty(),minor_breaks=scales::breaks_width(1))
scale_x_continuous(limits=xlim_year, breaks=scales::breaks_pretty(),minor_breaks=scales::breaks_width(1))
} else {
g1 <- ggplot(d_tidy) +
geom_point(aes(x=year, y=resid, colour = Index_Label), size = 2) +
facet_wrap(~Index_Label, scale = if(plot_scale) "free" else "fixed",axes="all_x")+
geom_hline(yintercept = 0, linewidth = 1)+
xlab("Year") +
xlim(xlim_year) +
#xlim(xlim_year) +
ylab("log(Residual)") +
theme_SH(base_size = 14)+
geom_label(data = rho_data,
Expand All @@ -788,13 +788,13 @@ plot_residual_vpa2 <- function(res, index_name = NULL, plot_smooth = FALSE, plot
", rho=", round(ar1,2), signif)),
vjust="inward", hjust="inward")+
guides(x=guide_axis(minor.ticks = TRUE))+
scale_x_continuous(breaks=scales::breaks_pretty(),minor_breaks=scales::breaks_width(1))
scale_x_continuous(limits=xlim_year, breaks=scales::breaks_pretty(),minor_breaks=scales::breaks_width(1))
g1_sd <- ggplot(d_tidy) +
geom_point(aes(x=year, y=sd.resid, colour = Index_Label), size = 2) +
facet_wrap(~Index_Label, scale = if(plot_scale) "fixed" else "free",axes="all_x")+
geom_hline(yintercept = 0, linewidth = 1)+
xlab("Year") +
xlim(xlim_year) +
#xlim(xlim_year) +
ylab("log(Residual)") +
theme_SH(base_size = 14)+
geom_label(data = rho_data,
Expand All @@ -803,7 +803,7 @@ plot_residual_vpa2 <- function(res, index_name = NULL, plot_smooth = FALSE, plot
", rho=", round(ar1,2), signif)),
vjust="inward", hjust="inward")+
guides(x=guide_axis(minor.ticks = TRUE))+
scale_x_continuous(breaks=scales::breaks_pretty(),minor_breaks=scales::breaks_width(1))
scale_x_continuous(limits=xlim_year, breaks=scales::breaks_pretty(),minor_breaks=scales::breaks_width(1))
}
if(plot_smooth) g1 <- g1 + geom_smooth(aes(x=year, y=resid, colour = Index_Label), lwd = 0.5, se=FALSE, lty=2)
if(plot_smooth) g1_sd <- g1_sd + geom_smooth(aes(x=year, y=sd.resid, colour = Index_Label), lwd = 0.5, se=FALSE, lty=2)
Expand All @@ -812,12 +812,13 @@ plot_residual_vpa2 <- function(res, index_name = NULL, plot_smooth = FALSE, plot
geom_point(aes(x=year, y=obs, colour = Index_Label), size = 2) +
geom_line(aes(x=year, y=pred, colour = Index_Label), linewidth = 1) +
facet_wrap(~Index_Label, scale="free") +
xlim(xlim_year) + ylim(0, NA) +
#xlim(xlim_year) +
ylim(0, NA) +
ylab("Abundance index") +
xlab("Year") +
theme_SH(base_size = 14)+
guides(x=guide_axis(minor.ticks = TRUE))+
scale_x_continuous(breaks=scales::breaks_pretty(),minor_breaks=scales::breaks_width(1))
scale_x_continuous(limits=xlim_year, breaks=scales::breaks_pretty(),minor_breaks=scales::breaks_width(1))

# 資源量と指数の(非)線形性のプロット
Lab_tmp <- unique(d_tidy$Index_Label)
Expand Down

0 comments on commit 97106f8

Please sign in to comment.