Skip to content

Commit

Permalink
relocating the figures in articles, trying knitr::include_graphics
Browse files Browse the repository at this point in the history
  • Loading branch information
m-delem committed Oct 24, 2024
1 parent 7a60f61 commit 28f2641
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions vignettes/articles/create-sticker.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ title: "Creating this package's sticker"
```{r}
#| include: false
knitr::opts_chunk$set(
warning = FALSE,
message = FALSE,
collapse = TRUE,
comment = "#>"
)
```

Quick article to document the process of creating a sticker for this package (which I initially did for fun and learning purposes). I use the `pacman` package in my setup to conveniently check if installed/install/load the necessary packages, all in one go.
Quick article to document the process of creating a sticker for this package (which I initially did for fun and learning purposes). I use the `pacman` package in my setup to conveniently check "if installed"/install/load the necessary packages, all in one go.

```{r}
#| label: setup
#| eval: true
if (!requireNamespace("pacman", quietly = TRUE)) {
install.packages("pacman")
Expand All @@ -24,31 +27,35 @@ pacman::p_load(
ggpath, # to read the images directly from the paths
sysfonts, # to use a custom font
showtext, # to use a custom font
here, # to use relative paths
knitr # to include the images in the document
# cropcircles, # to crop the image in a hexagonal shape
here # to use relative paths
)
# cropcircles is commented because it has a weird interference with GHA
```

First, I put a little square shaped drawing of mine, named `delemr_drawing.png`,
in the `man/figures` folder of the package.

```{r}
```{r out.width="50%"}
#| label: raw
#| fig-width: 4
#| fig-height: 3.88
#| fig.alt: >
#| Raw image of my drawing.
image_path <- "../../man/figures/delemr_drawing.png"
stick_path <- "../../man/figures/delemr_sticker.png"
logo_path <- "../../man/figures/logo.png"
image_path <- "delemr_drawing.png"
stick_path <- "delemr_sticker.png"
ggplot() +
ggplot() +
geom_from_path(aes(.5, .5, path = image_path)) +
theme_void()
knitr::include_graphics(image_path)
```



Time to build the sticker.

- I used the `hex_crop()` function to crop the image in a hexagonal shape,
Expand Down Expand Up @@ -102,19 +109,21 @@ ggsave(
)
```

```{r}
```{r out.width="50%"}
#| label: sticker
#| fig-width: 5.18
#| fig-height: 6
#| fig.alt: >
#| Final sticker with the package name.
# displaying the saved image
ggplot() +
ggplot() +
geom_from_path(aes(.5, .5, path = stick_path)) +
scale_x_continuous(limits = c(0, 1), expand = c(0, 0)) +
scale_y_continuous(limits = c(0, 1), expand = c(0, 0)) +
theme_void()
knitr::include_graphics(stick_path)
```

Now to use the sticker as a package logo, it needs to be a bit smaller,
Expand All @@ -124,7 +133,7 @@ and this is conveniently taken care of by the `usethis::use_logo()` function.
#| label: logo
#| eval: false
use_logo(stick_path)
usethis::use_logo(stick_path)
```

Done!
File renamed without changes
File renamed without changes

0 comments on commit 28f2641

Please sign in to comment.