Skip to content

Commit

Permalink
Add missing conditional execution of 'ggrepel'
Browse files Browse the repository at this point in the history
An object was created in a chunk run only with 'ggrepel' available, but used in unprotected chunks. In addition found additional unprotected chunks calling 'ggrepel'.
  • Loading branch information
aphalo committed Jun 30, 2024
1 parent 79c84aa commit 4f015cb
Show file tree
Hide file tree
Showing 6 changed files with 399 additions and 402 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: ggpp
Type: Package
Title: Grammar Extensions to 'ggplot2'
Version: 0.5.8
Date: 2024-06-26
Version: 0.5.8-1
Date: 2024-06-30
Authors@R:
c(
person("Pedro J.", "Aphalo", email = "pedro.aphalo@helsinki.fi", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-3385-972X")),
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ editor_options:
wrap: 72
---

# ggpp 0.5.8
# ggpp 0.5.8-1

- Fix wrong test for availability of 'gginnards' in examples (reported by
_Joshua Ulrich_ in issue #53).
- Add to vignette _Combining repulsion and nudging_ three missing tests for
availability of package 'ggrepel'.
- Revise `position_nudge_to()` to support expansion and contraction of the
range within which to spread the positions.

Expand Down
2 changes: 2 additions & 0 deletions man/ggpp-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions vignettes/nudge-examples.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ ggplot(df, aes(x, y, label = l)) +
hjust = "left") +
expand_limits(x = 2.3)

## ----eval=eval_ggrepel--------------------------------------------------------
## -----------------------------------------------------------------------------
## Example data frame where each species' principal components have been computed.
df1 <- data.frame(
Species = paste("Species",1:5),
PC1 = c(-4, -3.5, 1, 2, 3),
PC2 = c(-1, -1, 0, -0.5, 0.7))

## ----eval=eval_ggrepel--------------------------------------------------------
ggplot(df1, aes(x=PC1, y = PC2, label = Species, colour = Species)) +
geom_hline(aes(yintercept = 0), linewidth = .2) +
geom_vline(aes(xintercept = 0), linewidth = .2) +
Expand All @@ -78,7 +79,7 @@ ggplot(df1, aes(x=PC1, y = PC2, label = Species, colour = Species)) +
coord_fixed() +
theme(legend.position = "none")

## -----------------------------------------------------------------------------
## ----eval=eval_ggrepel--------------------------------------------------------
ggplot(df1, aes(x=PC1, y = PC2, label = Species, colour = Species)) +
geom_hline(aes(yintercept = 0), linewidth = .2) +
geom_vline(aes(xintercept = 0), linewidth = .2) +
Expand Down Expand Up @@ -350,14 +351,11 @@ ggplot(data = d, aes(x, y, label = lab, colour = group)) +
geom_point()

## -----------------------------------------------------------------------------
library(ggplot2)
library(ggpp)
library(ggrepel)
syms = c(letters[1:5], LETTERS[1:5], 0:9)
labs = do.call(paste0, expand.grid(syms, syms))
dset = data.frame(x=rnorm(1e3), y=rnorm(1e3), label=sample(labs, 1e3, replace=TRUE))

## -----------------------------------------------------------------------------
## ----eval=eval_ggrepel--------------------------------------------------------
ggplot(dset, aes(x=x, y=y, label = label)) +
geom_point(colour = "grey85") +
stat_dens2d_filter(geom = "text_repel",
Expand Down Expand Up @@ -466,7 +464,7 @@ ggplot(df, aes(x, yy)) +
box.padding = 0,
min.segment.length = 0)

## -----------------------------------------------------------------------------
## ----eval=eval_ggrepel--------------------------------------------------------
ggplot(df, aes(x, yy)) +
geom_point() +
stat_smooth(method = "lm",
Expand Down
15 changes: 7 additions & 8 deletions vignettes/nudge-examples.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,18 @@ respective default justification approaches.

---

A usually more problematic example is the labeling of loadings in PCA
A usually more problematic example is the labelling of loadings in PCA
and similar biplots.

```{r, eval=eval_ggrepel}
```{r}
## Example data frame where each species' principal components have been computed.
df1 <- data.frame(
Species = paste("Species",1:5),
PC1 = c(-4, -3.5, 1, 2, 3),
PC2 = c(-1, -1, 0, -0.5, 0.7))
```

```{r, eval=eval_ggrepel}
ggplot(df1, aes(x=PC1, y = PC2, label = Species, colour = Species)) +
geom_hline(aes(yintercept = 0), linewidth = .2) +
geom_vline(aes(xintercept = 0), linewidth = .2) +
Expand All @@ -273,7 +275,7 @@ ggplot(df1, aes(x=PC1, y = PC2, label = Species, colour = Species)) +
The use of `position_nudge_center()` together with repulsion, shown above,
results a much better plot than using only repulsion.

```{r}
```{r, eval=eval_ggrepel}
ggplot(df1, aes(x=PC1, y = PC2, label = Species, colour = Species)) +
geom_hline(aes(yintercept = 0), linewidth = .2) +
geom_vline(aes(xintercept = 0), linewidth = .2) +
Expand Down Expand Up @@ -696,15 +698,12 @@ GitHub by Michael Schubert, made possible by parameter `keep.these` added for
this and similar use cases.

```{r}
library(ggplot2)
library(ggpp)
library(ggrepel)
syms = c(letters[1:5], LETTERS[1:5], 0:9)
labs = do.call(paste0, expand.grid(syms, syms))
dset = data.frame(x=rnorm(1e3), y=rnorm(1e3), label=sample(labs, 1e3, replace=TRUE))
```

```{r}
```{r, eval=eval_ggrepel}
ggplot(dset, aes(x=x, y=y, label = label)) +
geom_point(colour = "grey85") +
stat_dens2d_filter(geom = "text_repel",
Expand Down Expand Up @@ -909,7 +908,7 @@ Nudging plus repulsion, shown next, will be compared to
alternatives. In this case we assume no linking segments are desired as
there is enough space for the data labels to remain near the observations.

```{r}
```{r, eval=eval_ggrepel}
ggplot(df, aes(x, yy)) +
geom_point() +
stat_smooth(method = "lm",
Expand Down
Loading

0 comments on commit 4f015cb

Please sign in to comment.