Skip to content

Commit 592534b

Browse files
committed
Revert "fix linetype scale"
This reverts commit 99a1222.
1 parent 6821200 commit 592534b

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

Diff for: scales-other.qmd

+16-15
Original file line numberDiff line numberDiff line change
@@ -245,25 +245,26 @@ base <- ggplot(df, aes(linetype = value)) +
245245
base
246246
```
247247

248-
You can control the line type by specifying a string with up to 8 hexadecimal values (i.e., from 0 to F).
249-
In this specification, the first value is the length of the first line segment, the second value is the length of the first space between segments, and so on.
250-
This allows you to specify your own line types using `scale_linetype_manual()`:
248+
You can control the line type by specifying a string with up to 8 hexadecimal values (i.e., from 0 to F). In this specification, the first value is the length of the first line segment, the second value is the length of the first space between segments, and so on. This allows you to specify your own line types using `scale_linetype_manual()`, or alternatively, by passing a custom function to the `palette` argument:
251249

252250
```{r}
253251
#| eval: false
254-
types <- c(
255-
"55",
256-
"75",
257-
"95",
258-
"1115",
259-
"111115",
260-
"11111115",
261-
"5158",
262-
"9198",
263-
"c1c8"
264-
)
252+
linetypes <- function(n) {
253+
types <- c(
254+
"55",
255+
"75",
256+
"95",
257+
"1115",
258+
"111115",
259+
"11111115",
260+
"5158",
261+
"9198",
262+
"c1c8"
263+
)
264+
return(types[seq_len(n)])
265+
}
265266
266-
base + scale_linetype_manual(values = linetypes)
267+
base + scale_linetype(palette = linetypes)
267268
```
268269

269270
Note that the last four lines are blank, because the `linetypes()` function defined above returns `NA` when the number of categories exceeds 9. The `scale_linetype()` function contains a `na.value` argument used to specify what kind of line is plotted for these values. By default this produces a blank line, but you can override this by setting `na.value = "dotted"`:

0 commit comments

Comments
 (0)