Learn R Programming

ggpp (version 0.4.3)

geom_point_s: Points linked by a segment

Description

The "point_s" geom provides a superset of the capabilities of geom "point" from package 'ggplot2' by allowing plotting of segments joining the original position of displaced observations to their current potition rendered as points or graphic symbols. Displacements by position functions from packages 'ggpp' and 'ggrepel' are supported.

Usage

geom_point_s(
  mapping = NULL,
  data = NULL,
  stat = "identity",
  position = "identity",
  ...,
  nudge_x = 0,
  nudge_y = 0,
  arrow = NULL,
  add.segments = TRUE,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping

Set of aesthetic mappings created by aes. If specified and inherit.aes = TRUE (the default), is combined with the default mapping at the top level of the plot. You only need to supply mapping if there isn't a mapping defined for the plot.

data

A data frame. If specified, overrides the default data frame defined at the top level of the plot.

stat

The statistical transformation to use on the data for this layer, as a string.

position

Position adjustment, either as a string, or the result of a call to a position adjustment function.

...

other arguments passed on to layer. There are three types of arguments you can use here:

  • Aesthetics: to set an aesthetic to a fixed value, like colour = "red" or size = 3.

  • Other arguments to the layer, for example you override the default stat associated with the layer.

  • Other arguments passed on to the stat.

nudge_x, nudge_y

Horizontal and vertical adjustments to nudge the starting position of each text label. The units for nudge_x and nudge_y are the same as for the data units on the x-axis and y-axis.

arrow

specification for arrow heads, as created by arrow

add.segments

logical Display connecting segments or arrows between original positions and displaced ones if both are available.

na.rm

If FALSE (the default), removes missing values with a warning. If TRUE silently removes missing values.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders.

Value

A plot layer instance.

Details

The plotting of segments is similar in idea at that available in geom_text_repel and relies on position functions that rename instead of removing the original original x and y coordinates from the data object.

By default this geom uses position_nudge_center which is backwards compatible with position_nudge but provides additional control on the direction of the nudging. In contrast to position_nudge, position_nudge_center and all other position functions defined in packaged 'ggpp' and 'ggrepel' keep the original coordinates thus allowing the plotting of connecting segments and arrows.

See Also

geom_point, geom_text_s, position_nudge_keep, position_nudge_to, position_jitternudge, position_dodgenudge and position_stacknudge.

Examples

Run this code
# NOT RUN {
# Same output as with geom_point()
ggplot(mpg[1:20, ],
       aes(cyl, hwy)) +
  geom_point_s()

ggplot(mpg[1:20, ],
       aes(cyl, hwy, label = drv)) +
  geom_point_s(position = position_nudge_keep(x = 0.2),
               color = "red",
               segment.colour = "brown") +
  geom_point_s()

ggplot(mpg[1:20, ],
       aes(cyl, hwy, label = drv)) +
  geom_point_s(position = position_nudge_keep(x = 0.2),
               color = "red",
               segment.colour = "brown") +
  geom_point_s()

ggplot(mpg[1:50, ],
       aes(cyl, hwy, label = drv)) +
  geom_point_s(position = position_jitternudge(width = 0.66, height = 2,
                                               seed = 456,
                                               nudge.from = "jittered",
                                               kept.origin = "original"),
               color = "red",
               arrow = grid::arrow(length = grid::unit(0.4, "lines"))) +
  geom_point_s()

# }

Run the code above in your browser using DataLab