Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for custom linetypes #792

Open
machow opened this issue May 28, 2024 · 0 comments
Open

Support for custom linetypes #792

machow opened this issue May 28, 2024 · 0 comments

Comments

@machow
Copy link
Contributor

machow commented May 28, 2024

The ggplot aesthetic specification doc gives a handy example of customizing linetypes, using the following format:

library(ggplot2)

lty <- c("11", "18", "1f", "81", "88", "8f", "f1", "f8", "ff")
linetypes <- data.frame(
  y = seq_along(lty),
  lty = lty
) 
ggplot(linetypes, aes(0, y)) + 
  geom_segment(aes(xend = 5, yend = y, linetype = lty)) + 
  scale_linetype_identity() + 
  geom_text(aes(label = lty), hjust = 0, nudge_y = 0.2) +
  scale_x_continuous(NULL, breaks = NULL) + 
  scale_y_reverse(NULL, breaks = NULL)
image

It could be handy to allow for something similar.

Background on ggplot2 syntax

ggplot2's linetype support matches base R's linetype specification (h/t tidyverse folks for the pointer):

image

This syntax allows each character in a string to specify width of "on" and "off" line parts. For example,

  • "12" : 1 on, 2 off, repeat...
  • "1234" : 1 on, 2 off, 3 on, 4 off, repeat...

It uses hexadecimal format, so allows for..

  • "1f" : 1 on, 15 off

Proposed syntax

It seems like the R syntax could be supported directly. But I wonder if using an explicit separator might help clean things up a bit?

Something like:

  • "1-2" : 1 on, 2 off
  • "1-2-3-4": 1 on, 2 off, 3 on, 4 off
  • "1-15": 1 on, 15 off

This way, it's clear what separates each piece, and people are constrained to a single character per part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants