Skip to content

Aligning geoms with preserve = "single" appears impossible #2712

Closed
@Ax3man

Description

@Ax3man

I want to plot a geom without with together with a geom that does have width, e.g. points and boxplots.

Not all factor combinations are present.

The default of adjusting the width (preserve = 'total') works fine. But when maintaining the box widths with preserve = 'single' I can no longer do the same for the points.

library(ggplot2)

ggplot(mtcars, aes(factor(gear), mpg, fill = factor(am))) + 
  geom_boxplot(position = position_dodge(preserve = 'total')) +
  geom_point(position = position_dodge(0.75, preserve = 'total'))

ggplot(mtcars, aes(factor(gear), mpg, fill = factor(am))) + 
  geom_boxplot(position = position_dodge(preserve = 'single')) +
  geom_point(position = position_dodge(0.75, preserve = 'total'))

ggplot(mtcars, aes(factor(gear), mpg, fill = factor(am))) + 
  geom_boxplot(position = position_dodge(preserve = 'single')) +
  geom_point(position = position_dodge(0.75, preserve = 'single'))
#> Warning in max(table(panel$xmin)): no non-missing arguments to max;
#> returning -Inf

Created on 2018-06-24 by the reprex package (v0.2.0).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions