grantmcdermott / tinyplot

Lightweight extension of the base R graphics system
https://grantmcdermott.com/tinyplot
Apache License 2.0
211 stars 7 forks source link

Support type = "segments" #163

Closed grantmcdermott closed 3 weeks ago

grantmcdermott commented 3 weeks ago

Closes #162.

Examples:

pkgload::load_all("~/Documents/Projects/tinyplot/")
#> ℹ Loading tinyplot

set.seed(42L)
x = stats::runif(12); y <- stats::rnorm(12)
i = order(x, y); x <- x[i]; y <- y[i]
s = seq(length(x)-1)  # one shorter than data
s = s[-length(s)]
grp = rep(LETTERS[1:2], 5)

plt(
  xmin = x[s], ymin = y[s], xmax = x[s+2], ymax = y[s+2],
  by = grp,
  type = "segments"
)


# also vary lty and lwd by groups
plt(
  xmin = x[s], ymin = y[s], xmax = x[s+2], ymax = y[s+2],
  by = grp,
  lty = "by", lwd = "by",
  type = "segments"
)


# xmin = xmax
plt(
  xmin = x[s], ymin = y[s], xmax = x[s], ymax = y[s+2],
  by = grp,
  lty = "by", lwd = "by",
  type = "segments"
)


# ymin = ymax
plt(
  xmin = x[s], ymin = y[s], xmax = x[s+2], ymax = y[s],
  by = grp,
  lty = "by", lwd = "by",
  type = "segments"
)

Created on 2024-07-07 with reprex v2.1.0