Skip to content
Merged
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
3 changes: 3 additions & 0 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Version: 1.1.0
Date: 2025-09-17 11:38:56 UTC
SHA: 54fed5bb7c0f4c027fbdab0a6f5a9acaed75e7f5
9 changes: 3 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ggpath
Title: Robust Image Rendering Support for 'ggplot2'
Version: 1.0.2.9002
Version: 1.1.0
Authors@R:
person("Sebastian", "Carl", , "[email protected]", role = c("aut", "cre", "cph"))
Description: A 'ggplot2' extension that enables robust image grobs in
Expand All @@ -14,7 +14,7 @@ Depends:
Imports:
cachem (>= 1.0.0),
cli (>= 3.0.0),
ggplot2 (>= 3.5.2.9002),
ggplot2 (>= 4.0.0),
grid,
magick (>= 2.7.3),
memoise (>= 2.0.0),
Expand All @@ -26,9 +26,6 @@ Suggests:
testthat (>= 3.0.0),
vdiffr (>= 1.0.2)
Config/testthat/edition: 3
Config/Needs/check: tidyverse/ggplot2
Config/Needs/website: tidyverse/ggplot2
Remotes: tidyverse/ggplot2
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
RoxygenNote: 7.3.3
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ggpath (development version)
# ggpath 1.1.0

ggpath now requires ggplot2 v4! This package is intended to be a ggplot2 extension
and if ggplot2 version jumps make breaking changes, then it's best for the extension
Expand Down
4 changes: 2 additions & 2 deletions R/build_grobs.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ build_grobs <- function(i, alpha, colour, path, data,
vp = grid::viewport(
x = grid::unit(data$x[i], "npc"),
y = grid::unit(data$y[i], "npc"),
width = grid::unit(data$width[i], "npc"),
height = grid::unit(data$height[i], "npc"),
width = data$width[i],
height = data$height[i],
angle = data$angle[i]
),
just = c(data$hjust[i], data$vjust[i]),
Expand Down
4 changes: 2 additions & 2 deletions R/theme_element.R
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ S7::method(element_grob, element_path) <- function(
y = as.numeric(y),
hjust = rep(hj, n),
vjust = rep(vj, n),
width = rep(1, n),
height = rep(1, n),
width = rep(size, n),
height = rep(size, n),
angle = rep(angle, n)
),
is_theme_element = TRUE
Expand Down
25 changes: 10 additions & 15 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The two main features to provide images in a ggplot are a geom (`geom_from_path(
The below examples use local image files that are shipped with the package. Let's locate the images first.

```{r}
local_r_logo <- system.file("r_logo.png", package = "ggpath")
r_logo <- "https://cran.r-project.org/Rlogo.svg"
local_background_image <- system.file("example_bg.jpg", package = "ggpath")
```

Expand All @@ -59,7 +59,7 @@ Now, we can make a simple plot, where we use the logo image like a point by repl
```{r dpi=300}
library(ggplot2)
library(ggpath)
plot_data <- data.frame(x = c(-1, 1), y = 1, path = local_r_logo)
plot_data <- data.frame(x = c(-1, 1), y = 1, path = r_logo)
ggplot(plot_data, aes(x = x, y = y)) +
geom_from_path(aes(path = path), width = 0.2) +
coord_cartesian(xlim = c(-2, 2)) +
Expand All @@ -71,16 +71,16 @@ ggplot(plot_data, aes(x = x, y = y)) +
We can build on top of that by adding new axis labels, axis titles, plot title and subtitle, or a caption and using a ggpath theme element. Note the usage of transparency with the `alpha` argument, the justification with the `hjust`/`vjust` arguments, or the rotation with the `angle` argument.

```{r dpi=300}
ggplot(plot_data, aes(x = x, y = local_r_logo)) +
ggplot(plot_data, aes(x = x, y = r_logo)) +
geom_from_path(aes(path = path), width = 0.2, alpha = 0.2) +
coord_cartesian(xlim = c(-2, 2)) +
theme_minimal() +
labs(
title = local_r_logo,
subtitle = local_r_logo,
x = local_r_logo,
y = local_r_logo,
caption = local_r_logo
title = r_logo,
subtitle = r_logo,
x = r_logo,
y = r_logo,
caption = r_logo
) +
theme(
plot.caption = element_path(hjust = 1, size = grid::unit(4, "lines")),
Expand All @@ -105,7 +105,7 @@ ggplot(plot_data, aes(x = x, y = 1)) +
x = "x axis label",
y = "y axis label",
caption = "useful caption",
tag = local_r_logo
tag = r_logo
) +
theme(
plot.tag = element_path(size = 2, vjust = 1, alpha = 0.7),
Expand All @@ -117,7 +117,7 @@ Please note how to place the image in the whole plot area via `plot.tag.position

### Images in Theme Elements (element_raster)

The second theme element, `element_raster()`, allows rendering of images in the plot background. It is a replacement for `ggplot2::element_rect()`. In the following example, we plot the two logos again and now set a sample background. The sample background is a photo by [Dan Cristian Pădureț](https://unsplash.com/@dancristianpaduret?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash) on [Unsplash](https://unsplash.com/photos/white-printer-paper-on-brown-textile-izq7BRX6xfw?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash).
The second theme element, `element_raster()`, allows rendering of images in the plot background. It is a replacement for `ggplot2::element_rect()`. In the following example, we plot the two logos again and now set a sample background. The sample background is a photo by Dan Cristian Pădureț on Unsplash.

```{r dpi=300}
ggplot(plot_data, aes(x = x, y = y)) +
Expand Down Expand Up @@ -171,8 +171,3 @@ There are some downsides compared to the above mentioned packages, e.g.

- cannot combine images and text to a grob as ggtext can with [`element_markdown`](https://wilkelab.org/ggtext/reference/element_markdown.html),
- cannot modify css parts of svgs as [ggsvg can](https://github.com/coolbutuseless/ggsvg#styling-svg-with-css-aesthetics-example-1).





23 changes: 10 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The below examples use local image files that are shipped with the
package. Let’s locate the images first.

``` r
local_r_logo <- system.file("r_logo.png", package = "ggpath")
r_logo <- "https://cran.r-project.org/Rlogo.svg"
local_background_image <- system.file("example_bg.jpg", package = "ggpath")
```

Expand All @@ -65,7 +65,7 @@ by replacing the local path with the actual image.
``` r
library(ggplot2)
library(ggpath)
plot_data <- data.frame(x = c(-1, 1), y = 1, path = local_r_logo)
plot_data <- data.frame(x = c(-1, 1), y = 1, path = r_logo)
ggplot(plot_data, aes(x = x, y = y)) +
geom_from_path(aes(path = path), width = 0.2) +
coord_cartesian(xlim = c(-2, 2)) +
Expand All @@ -83,16 +83,16 @@ with the `hjust`/`vjust` arguments, or the rotation with the `angle`
argument.

``` r
ggplot(plot_data, aes(x = x, y = local_r_logo)) +
ggplot(plot_data, aes(x = x, y = r_logo)) +
geom_from_path(aes(path = path), width = 0.2, alpha = 0.2) +
coord_cartesian(xlim = c(-2, 2)) +
theme_minimal() +
labs(
title = local_r_logo,
subtitle = local_r_logo,
x = local_r_logo,
y = local_r_logo,
caption = local_r_logo
title = r_logo,
subtitle = r_logo,
x = r_logo,
y = r_logo,
caption = r_logo
) +
theme(
plot.caption = element_path(hjust = 1, size = grid::unit(4, "lines")),
Expand Down Expand Up @@ -123,7 +123,7 @@ ggplot(plot_data, aes(x = x, y = 1)) +
x = "x axis label",
y = "y axis label",
caption = "useful caption",
tag = local_r_logo
tag = r_logo
) +
theme(
plot.tag = element_path(size = 2, vjust = 1, alpha = 0.7),
Expand All @@ -143,10 +143,7 @@ The second theme element, `element_raster()`, allows rendering of images
in the plot background. It is a replacement for
`ggplot2::element_rect()`. In the following example, we plot the two
logos again and now set a sample background. The sample background is a
photo by [Dan Cristian
Pădureț](https://unsplash.com/@dancristianpaduret?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash)
on
[Unsplash](https://unsplash.com/photos/white-printer-paper-on-brown-textile-izq7BRX6xfw?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash).
photo by Dan Cristian Pădureț on Unsplash.

``` r
ggplot(plot_data, aes(x = x, y = y)) +
Expand Down
2 changes: 1 addition & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Submission

This is a patch release that fixes check NOTEs
This is a patch release that fixes failing tests due to ggplot2 v4 release.

## R CMD check results

Expand Down
Binary file modified man/figures/README-unnamed-chunk-4-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-5-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-6-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-7-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions tests/testthat/_snaps/theme-elements/p1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions tests/testthat/_snaps/theme-elements/p2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading