Skip to content

Commit

Permalink
Disable broken blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonthegeek committed Jun 25, 2024
1 parent eaa4146 commit 995e928
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 29 deletions.
3 changes: 1 addition & 2 deletions 11-Colour_scales_and_legends.Rmd
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Colour Scales and Legends

```{r 11-library, include=FALSE}
library(ggplot2)
library(dplyr)
library(scico)
```


Expand Down
30 changes: 5 additions & 25 deletions 12-Other_aesthetics.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ To learn about several other aesthetics that ggplot2 can use to represent data,
- identity scales




```{r 12-library 01, include=FALSE}
library(ggplot2)
```


Expand All @@ -35,7 +31,6 @@ base <- ggplot(mpg, aes(displ, hwy, size = cyl)) +
base
base + scale_size(range = c(1, 2))
```

There are several size scales:
Expand All @@ -54,7 +49,7 @@ There are several size scales:
There are situations where area scaling is undesirable, and for such situations *scale_radius()* may be more appropriate. For example, consider a data set containing astronomical data that includes the radius of different planets:


```{r radius size scales 01, echo=FALSE }
```{r radius size scales 01, echo = FALSE}
planets <- data.frame(
name = c("Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"),
type = c(rep("Inner", 4), rep("Outer", 4)),
Expand Down Expand Up @@ -87,25 +82,19 @@ Binned size scales work similarly to binned scales for colour and position aesth


```{r binned size scales 01}
base <- ggplot(mpg, aes(displ, manufacturer, size = hwy)) +
geom_point(alpha = .2) +
scale_size_binned()
base
```

Unlike *guide_legend()*, the guide created for a binned scale by *guide_bins()* does not organize the individual keys into a table. Instead they are arranged in a column (or row) along a single vertical (or horizontal) axis, which by default is displayed with its own axis. The important arguments to guide_bins() are listed below:

- **axis** indicates whether the axis should be drawn (default is TRUE)



```{r binned size scales 02}
base + guides(size = guide_bins(axis = FALSE))
```

- **direction** is a character string specifying the direction of the guide, either "vertical" (the default) or "horizontal"
Expand Down Expand Up @@ -149,13 +138,11 @@ The default *scale_shape()* function contains a single argument: **set solid = T


```{r shape 01}
base <- ggplot(mpg, aes(displ, hwy, shape = factor(cyl))) +
geom_point()
base
base + scale_shape(solid = FALSE)
```


Expand All @@ -176,18 +163,15 @@ It is possible to map a variable onto the linetype aesthetic, which works best f


```{r line type 01}
ggplot(economics_long, aes(date, value01, linetype = variable)) +
geom_line()
```

With five categories the above plot is quite difficult to read.

The default “palette” for linetype is supplied by the *scales::linetype_pal()* function, and includes the 13 linetypes shown below:



```{r line types 02}
df <- data.frame(value = letters[1:13])
base <- ggplot(df, aes(linetype = value)) +
Expand All @@ -211,7 +195,8 @@ This allows you to specify your own line types using *scale_linetype_manual()*,

Note that the last four lines are blank, because the *linetypes()* function defined above returns NA when the number of categories exceeds 9.

```{r line types 03}
```{r line types 03, eval = FALSE}
# TODO: Eval turned off due to error, you should fix this!
linetypes <- function(n) {
types <- c("55", "75", "95", "1115", "111115", "11111115",
"5158", "9198", "c1c8")
Expand All @@ -227,7 +212,8 @@ The *scale_linetype()* function contains a na.value argument used to specify wha



```{r line types 04}
```{r line types 04, eval = FALSE}
# TODO: Eval turned off due to error, you should fix this!
base + scale_linetype(palette = linetypes, na.value = "dotted")
```

Expand Down Expand Up @@ -262,23 +248,17 @@ ggplot(huron, aes(year)) +
ggplot(huron, aes(year)) +
geom_line(aes(y = level + 5, colour = "above")) +
geom_line(aes(y = level - 5, colour = "below"))
```

- And then tell the scale how to map labels to colours:



```{r manual scales 03}
ggplot(huron, aes(year)) +
geom_line(aes(y = level + 5, colour = "above")) +
geom_line(aes(y = level - 5, colour = "below")) +
scale_colour_manual("Direction",
values = c("above" = "red", "below" = "blue")
)
```


Expand Down
6 changes: 4 additions & 2 deletions 19-ggplot2-internals.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -662,14 +662,16 @@ p +

This is the output of the `guide_train()` method defined for `guide_legend()`. The most important piece of it is `key`, which is the data associated with the legend.

```{r 20-57}
```{r 20-57, eval = FALSE}
# TODO: The unexported function no longer exists, so we had to turn off eval.
names( ggtrace_inspect_return(p, ggplot2:::guide_train.legend) )
ggtrace_inspect_return(p, ggplot2:::guide_train.legend)$key
```

The output of `guide_train()` is passed to `guide_gengrob()`. This is the output of the `guide_gebgrob()` method defined for `guide_legend()`:

```{r 20-58}
```{r 20-58, eval = FALSE}
# TODO: The unexported function no longer exists, so we had to turn off eval.
legend_gengrob <- ggtrace_inspect_return(p, ggplot2:::guide_gengrob.legend)
grid.newpage()
grid.draw(legend_gengrob)
Expand Down

0 comments on commit 995e928

Please sign in to comment.