From a5326b406839991060cabefe259e243edc7ec37b Mon Sep 17 00:00:00 2001 From: jahn Date: Fri, 24 Nov 2023 14:47:23 +0100 Subject: [PATCH] feat: error margins can now be plotted for numeric x vars, not only factors --- R/panel_barplot.R | 9 +++++++-- R/panel_errbars.R | 10 ++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/R/panel_barplot.R b/R/panel_barplot.R index bf5a554..857cfc7 100644 --- a/R/panel_barplot.R +++ b/R/panel_barplot.R @@ -181,8 +181,13 @@ panel.barplot <- function (x, y, } x_s <- unique(x_sub) - if (is.factor(x_s)) x_s <- sort(as.numeric(x_s)) - if (beside) x_pos <- x_s + nudge[val] else x_pos <- x_s + if (is.factor(x_s)) { + x_s <- sort(as.numeric(x_s)) + if (beside) x_pos <- x_s + nudge[val] else x_pos <- x_s + } else { + if (beside) x_pos <- x_s + nudge[val] else x_pos <- x_s + x_s <- order(x_s) + } if (is.null(origin)) ybottom <- current.panel.limits()$ylim[1] else ybottom <- origin diff --git a/R/panel_errbars.R b/R/panel_errbars.R index e769865..b9b74bf 100644 --- a/R/panel_errbars.R +++ b/R/panel_errbars.R @@ -146,8 +146,14 @@ panel.errbars <- function (x, y, } x_s <- unique(x_sub) - if (is.factor(x_s)) x_s <- sort(as.numeric(x_s)) - if (beside) x_pos <- x_s + nudge[val] else x_pos <- x_s + if (is.factor(x_s)) { + x_s <- sort(as.numeric(x_s)) + if (beside) x_pos <- x_s + nudge[val] else x_pos <- x_s + } else { + if (beside) x_pos <- x_s + nudge[val] else x_pos <- x_s + x_s <- order(x_s) + } + Y <- as.matrix(cbind(means, means-lower, means+upper)) y_s <- Y[x_s, 1]