pubh (version 1.1.16)

gf_star: Annotating a plot to display differences between groups.

Description

gf_star Is a function used to display differences between groups (see details).

Usage

gf_star(fig, x1, y1, x2, y2, y3, legend = "*", ...)

Arguments

fig

A gformula object.

x1

Position in x for the start of the horizontal line.

y1

Position in y for the start of the vertical line, below to the horizontal line.

x2

Position in x for the end of the horizontal line.

y2

Position in y where the horizontal line is drawn.

y3

Position in y where the text is added.

legend

Character text used for annotating the plot.

...

Additional information passed to gf_text.

Details

This function draws an horizontal line from coordinate (x1, y2) to coordinate (x2, y2). Draws vertical lines below the horizontal line, towards data, from (x1, y1) to (x1, y2) and from (x2, y1) to (x2, y2). Finally, adds text above the horizontal line, at the mid point between x1 and x2. See examples.

Examples

Run this code
# NOT RUN {
data(kfm, package = "ISwR")
require(sjlabelled)
kfm = kfm %>%
  var_labels(
     dl.milk = 'Breast-milk intake (dl/day)',
     sex = 'Sex',
     weight = 'Child weight (kg)',
     ml.suppl = 'Milk substitute (ml/day)',
     mat.weight = 'Maternal weight (kg)',
     mat.height = 'Maternal height (cm)'
     )

kfm %>%
  box_plot(dl.milk ~ sex, fill='thistle', alpha = 0.8) %>%
  axis_labs() %>%
  gf_star(x1 = 1, y1 = 10.9, x2 = 2, y2 = 11, y3 = 11.2)

kfm %>%
  box_plot(dl.milk ~ sex, fill='thistle', alpha = 0.8) %>%
  axis_labs() %>%
  gf_star(1, 10.9, 2, 11, 11.4, legend = 'p = 0.035', size = 2.5)

data(energy, package = "ISwR")
energy = energy %>%
  var_labels(
    expend = 'Energy expenditure (MJ/day)',
    stature = 'Stature'
    )

energy %>%
  strip_error(expend ~ stature, col = 'red') %>%
  axis_labs() %>%
  gf_star(1, 13, 2, 13.2, 13.4, "**")
# }

Run the code above in your browser using DataLab