position_dodgex: Dodge overlapping objects side-to-side which can be shifted...

Description Usage Arguments Value See Also Examples

View source: R/position_dodgex.r

Description

Dodging preserves the vertical position of an geom while adjusting the horizontal position. position_dodgex2 is a special case of position_dodgex for arranging box plots, which can have variable widths. position_dodgex2 also works with bars and rectangles. But unlike position_dodgex, position_dodgex2 works without a grouping variable in a layer.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
position_dodgex(
  width = NULL,
  hexpand = NA,
  vexpand = NA,
  preserve = c("total", "single")
)

position_dodgex2(
  width = NULL,
  preserve = c("total", "single"),
  hexpand = NA,
  vexpand = NA,
  padding = 0.1,
  reverse = FALSE
)

Arguments

width

Dodging width, when different to the width of the individual elements. This is useful when you want to align narrow geoms with wider geoms.

hexpand

numeric, Horizon expand for geoms that have a position, default is NA.

vexpand

numeric, Vertical expand for geoms that have a position, default is NA.

preserve

Should dodging preserve the total width of all elements at a position, or the width of a single element?

padding

Padding between elements at the same position. Elements are shrunk by this proportion to allow space between them. Defaults to 0.1.

reverse

If TRUE, will reverse the default stacking order. This is useful if you're rotating both the plot and legend.

Value

position methods

See Also

Other position adjustments: position_identityx(), position_points_sinax()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
library(ggplot2)
library(patchwork)
iris$ID <- rep(c(rep("test1", 15), rep("test2", 15), rep("test3", 20)),3)
p <- ggplot(iris, aes(x=Species,y=Petal.Length,fill=ID))
p1 <- p + geom_bar(stat="identity",position=position_dodgex())
p2 <- p + geom_bar(stat="identity",position=position_dodgex(vexpand=5))
p3 <- ggplot(iris, aes(x=Petal.Length, y=Species, fill=ID)) +
      geom_bar(stat="identity", orientation="y",
               position=position_dodgex(hexpand=5))
p4 <- p1 + p2 + p3
p4
p5 <- p + geom_boxplot(position=position_dodgex2())
p6 <- p + geom_boxplot(position=position_dodgex2(vexpand=5))
p7 <- ggplot(iris, aes(x=Petal.Length, y=Species, fill=ID)) +
      geom_boxplot(orientation="y",
                   position=position_dodgex2(hexpand=5))
p8 <- p5 + p6 + p7
p8

Example output



ggtreeExtra documentation built on April 8, 2021, 6:01 p.m.