Author: Stefan McKinnon Edwards sme@iysik.com
Date: 2025-09-04

# Geoms in lemon

#### Stefan McKinnon Edwards sme@iysik.com

#### 2025-09-04

Deprecation notice: The `geom_pointline and geom_pointpath` have been deprecated in lemon v. 0.5.0. Instead, we refer to the similar geom in ggh4x.

In this vignette, we will demonstrate the two geoms: geom_pointpath and geom_siderange.

## geom_pointpath

`geom_pointline` simply combines `geom_point` and `geom_line`, while `geom_pointpath` combines `geom_point` and `geom_path`. The difference is that `geom_line` draws its lines through the data points, `geom_pointline` leaves a small aesthetic gap between the symbol and the line:

    library(ggplot2)
    library(ggh4x)
    library(gridExtra)

    data(sunspot.year)
    sunspots <- data.frame(count = as.numeric(sunspot.year), year = seq.int(start(sunspot.year)[1], end(sunspot.year)[1]))
    sunspots <- subset(sunspots, year > 1900)

    point <-  ggplot(sunspots, aes(x = year, y = count)) + geom_point() + geom_line() + labs(title = "geom_point + geom_line")
    pointline <- ggplot(sunspots, aes(x = year, y = count)) + geom_pointpath(mult = 0.4) + labs(title = 'ggh4x geom_pointline')
    grid.arrange(point, pointline)

### lemon and ggh4x

The geom `geom_pointpath` in ggh4x can be used as replacement for both lemon’s `geom_pointline` and `geom_pointpath`:

lemon | ggh4x
--- | ---
`geom_pointpath(distance = ...)` `geom_pointline(distance = ...)` | `geom_pointpath(mult = ...)` | The `mult` argument is a numeric value to scale the proportion of the gap.

## geom_siderange

The `geom_siderange` projects data onto the horizontal or vertical edge of the panels.

    library(lemon)
    x <- rnorm(25)
    df <- data.frame(x = x, y = x + rnorm(25, sd = 0.2),
                     a = sample(c("horse", "goat"), 25, replace = TRUE),
                     stringsAsFactors = FALSE)
    df$y <- with(df, ifelse(y > 1 & a == 'horse', 1, y))
    p <- ggplot(df, aes(x = x, y = y, colour = a)) + geom_point(shape = 1)

    p + geom_siderange(start = 19)

Capping the sideranges with different symbols:

    p + geom_siderange(start = 19, end = 22, fill='black', sides = 'b') +
      geom_siderange(sides = 'tl')

It also works with facets:

    p <- ggplot(mpg, aes(displ, hwy, colour = fl)) +
      geom_point() +
      facet_wrap(~class, nrow = 4)

    p + geom_siderange()