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

Avoid warning: remove legend using guide = "none" instead of guide = FALSE as of ggplot2 3.3.4 #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ch03.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,12 @@ ggplot(climate_sub, aes(x = Year, y = Anomaly10y, fill = pos)) +

There are a few problems with the first attempt. First, the colors are probably the reverse of what we want: usually, blue means cold and red means hot. Second, the legend is redundant and distracting.

We can change the colors with `scale_fill_manual()` and remove the legend with `guide = FALSE`, as shown in Figure \@ref(fig:FIG-BAR-GRAPH-COLOR-NEG2). We'll also add a thin black outline around each of the bars by setting `colour` and specifying `size`, which is the thickness of the outline (in millimeters):
We can change the colors with `scale_fill_manual()` and remove the legend with `guide = "none"`, as shown in Figure \@ref(fig:FIG-BAR-GRAPH-COLOR-NEG2). We'll also add a thin black outline around each of the bars by setting `colour` and specifying `size`, which is the thickness of the outline (in millimeters):

```{r FIG-BAR-GRAPH-COLOR-NEG2, fig.cap="Graph with customized colors and no legend", fig.width=10, fig.height=2.5, out.width="100%"}
ggplot(climate_sub, aes(x = Year, y = Anomaly10y, fill = pos)) +
geom_col(position = "identity", colour = "black", size = 0.25) +
scale_fill_manual(values = c("#CCEEFF", "#FFDDDD"), guide = FALSE)
scale_fill_manual(values = c("#CCEEFF", "#FFDDDD"), guide = "none")
```

### See Also
Expand Down Expand Up @@ -756,7 +756,7 @@ Another way to separate the two groups is to use facets, as shown in Figure \@re
ggplot(tophit, aes(x = avg, y = name)) +
geom_segment(aes(yend = name), xend = 0, colour = "grey50") +
geom_point(size = 3, aes(colour = lg)) +
scale_colour_brewer(palette = "Set1", limits = c("NL", "AL"), guide = FALSE) +
scale_colour_brewer(palette = "Set1", limits = c("NL", "AL"), guide = "none") +
theme_bw() +
theme(panel.grid.major.y = element_blank()) +
facet_grid(lg ~ ., scales = "free_y", space = "free_y")
Expand Down
4 changes: 2 additions & 2 deletions ch07.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ Then we'll plot this data with specified colors, and hiding the legend (Figure \
```{r FIG-ANNOTATE-HIGHLIGHT, fig.cap="Highlighting one item", fig.width=4, fig.height=4}
ggplot(pg_mod, aes(x = group, y = weight, fill = hl)) +
geom_boxplot() +
scale_fill_manual(values = c("grey85", "#FFDDCC"), guide = FALSE)
scale_fill_manual(values = c("grey85", "#FFDDCC"), guide = "none")
```

### Discussion
Expand All @@ -301,7 +301,7 @@ If you have a small number of items, as in this example, instead of creating a n
```{r eval=FALSE}
ggplot(PlantGrowth, aes(x = group, y = weight, fill = group)) +
geom_boxplot() +
scale_fill_manual(values = c("grey85", "grey85", "#FFDDCC"), guide = FALSE)
scale_fill_manual(values = c("grey85", "grey85", "#FFDDCC"), guide = "none")
```

### See Also
Expand Down
2 changes: 1 addition & 1 deletion ch12.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,6 @@ ggplot(cbi, aes(x = Year, y = Anomaly10y)) +
geom_area(aes(fill = valence), alpha = .4) +
geom_line() +
geom_hline(yintercept = 0) +
scale_fill_manual(values = c("#CCEEFF", "#FFDDDD"), guide = FALSE) +
scale_fill_manual(values = c("#CCEEFF", "#FFDDDD"), guide = "none") +
scale_x_continuous(expand = c(0, 0))
```