Skip to content

Commit cac6703

Browse files
committed
Use discrete_scale() instead of scale_linetype()
1 parent 592534b commit cac6703

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

scales-other.qmd

+8-4
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ 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). 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:
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()`, or alternatively, by passing a custom function to the `palette` argument:
249251

250252
```{r}
251253
#| eval: false
@@ -264,14 +266,16 @@ linetypes <- function(n) {
264266
return(types[seq_len(n)])
265267
}
266268
267-
base + scale_linetype(palette = linetypes)
269+
base + discrete_scale("linetype", palette = linetypes)
268270
```
269271

270-
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"`:
272+
Note that the last four lines are blank, because the `linetypes()` function defined above returns `NA` when the number of categories exceeds 9.
273+
The `discrete_scale()` function contains a `na.value` argument used to specify what kind of line is plotted for these values.
274+
By default this produces a blank line, but you can override this by setting `na.value = "dotted"`:
271275

272276
```{r}
273277
#| eval: false
274-
base + scale_linetype(palette = linetypes, na.value = "dotted")
278+
base + discrete_scale("linetype", palette = linetypes)
275279
```
276280

277281
Valid line types can be set using a human readable character string: `"blank"`, `"solid"`, `"dashed"`, `"dotted"`, `"dotdash"`, `"longdash"`, and `"twodash"` are all understood.

0 commit comments

Comments
 (0)