typestar

Trends in R

geom_smooth fits a line or a loess curve, with a confidence band.

library(ggplot2)
library(tibble)

set.seed(2)
runs <- tibble(
  session = rep(1:30, 2),
  lang = rep(c("r", "python"), each = 30),
  tpm = c(80 + 0.6 * 1:30 + rnorm(30, 0, 3),
          88 + 0.5 * 1:30 + rnorm(30, 0, 4))
)

trend <- ggplot(runs, aes(session, tpm, colour = lang)) +
  geom_point(alpha = 0.6) +
  geom_smooth(method = "lm", formula = y ~ x, se = TRUE) +
  labs(title = "Improvement over sessions")

print(length(trend$layers))
ggsave(tempfile(fileext = ".png"), trend, width = 5, height = 3, dpi = 100)

How it works

  1. method = \u0022lm\u0022 is the straight line, with standard errors.
  2. se = FALSE drops the ribbon.
  3. Mapping color fits one trend per group.

Keywords and builtins used here

The run, in numbers

Lines
18
Characters to type
495
Tokens
167
Three-star pace
100 tpm

At the three-star pace of 100 tokens a minute, this run takes about 100 seconds.

Type this snippet

Step 3 of 4 in Geometries, step 6 of 15 in ggplot2.

← Previous Next →