Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Position_dodge2 not properly centering error bars in bars #5448

Closed
otaviolovison opened this issue Oct 1, 2023 · 2 comments
Closed

Position_dodge2 not properly centering error bars in bars #5448

otaviolovison opened this issue Oct 1, 2023 · 2 comments
Labels
reprex needs a minimal reproducible example

Comments

@otaviolovison
Copy link

Hello! I believe there is a bug happening when using position_dodge2. When I create the plot with position_dodge, the error bars are properly centered in the bars. But I need to reverse the bars and error bars. So I need to use position_dodge2 (reverse = TRUE). But when I do that, the error bars are not properly centered. I have tried a lot of solutions, but nothing is working. Here follows the code:

bar_errorbar <- ggplot2::ggplot(error_bar_pivot_longer_tibble_summarised_ordered, # nolint: object_usage_linter.
ggplot2::aes(mean, name, fill = group)) + # nolint
ggplot2::geom_errorbar(
ggplot2::aes(xmax = mean + sd, xmin = 0),
position = ggplot2::position_dodge2(width = 0.8, reverse = TRUE),
width = 0.5,
size = 0.5,
color = "black"
) +
ggplot2::geom_bar(stat = "identity", position = ggplot2::position_dodge2(width = 0.8, reverse = TRUE),
width = 0.8) +
GGally::geom_stripped_cols(width = 10) +
ggplot2::scale_fill_manual(values = colors) +
ggplot2::scale_color_manual(values = colors) +
ggprism::theme_prism() +
ggplot2::scale_x_continuous(expand = c(0, 0),
guide = "prism_offset_minor",) +
ggplot2::scale_y_discrete(labels = rev(daa_results_filtered_sub_df[, x_lab])) +
ggplot2::labs(x = "Relative Abundance", y = NULL) +
ggplot2::theme(
axis.ticks.y = ggplot2::element_blank(),
axis.line.y = ggplot2::element_blank(),
axis.line.x = ggplot2::element_line(size = 0.5),
axis.ticks.x = ggplot2::element_line(size = 0.5),
panel.grid.major.y = ggplot2::element_blank(),
panel.grid.major.x = ggplot2::element_blank(),
axis.text = ggplot2::element_text(size = 10, color = "black"), # nolint
axis.text.x = ggplot2::element_text(margin = ggplot2::margin(r = 0)), # nolint
axis.text.y = ggplot2::element_text(
size = 10,
color = "black",
margin = ggplot2::margin(b = 6)
),
axis.title.x = ggplot2::element_text(
size = 10,
color = "black",
hjust = 0.5
),
legend.position = "right",
legend.key.size = ggplot2::unit(0.1, "cm"),
legend.direction = "vertical",
legend.justification = "left",
legend.text = ggplot2::element_text(size = 8, face = "bold"),
legend.box.just = "right",
plot.margin = ggplot2::margin(0, 0.5, 0.5, 0, unit = "cm")
) + ggplot2::coord_cartesian(clip = "off")

Maybe I am missing something, but, since I tried a lot to solve this issue without success, I believe there is a bug going on here.

Thanks so much for the attention.

@teunbrand
Copy link
Collaborator

Could I ask you to convert your example code to a self-contained, minimal, reproducible example? If you've never heard of a reprex, please read "Make a reprex". Currently, it is hard to see how the code you have provided interacts with data you have not provided and the code is intertwined with code that is probably unrelated to the problem (e.g. theme settings).

@teunbrand teunbrand added the reprex needs a minimal reproducible example label Oct 2, 2023
@teunbrand
Copy link
Collaborator

I'm going to close this issue. If you find a way to make a reprex of the issue, I'll re-open this.

@teunbrand teunbrand closed this as not planned Won't fix, can't repro, duplicate, stale Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reprex needs a minimal reproducible example
Projects
None yet
Development

No branches or pull requests

2 participants