Skip to content

geom_point_pattern() #54

Closed
Closed

Description

@Henryjean

Would love a way to fill in a geom_point with an image of my choice.

Effectively, what I'd like to be to do is re-create a chart like this one:

image

Each point on the chart would correspond to a different image url in my dataframe, which is then used to fill in the circle.

I can kind of do this with geom_polygon_pattern() but it'd be nice if I didn't have to draw the circle first

Activity

  1. added
    feature
    on Oct 20, 2021
  2. changed the title [-]Support for geom_point or some kind of circle?[FEAT][/-] [+]Support for 'geom_circle()'[/+] on Oct 20, 2021
  3. coolbutuseless commented on Nov 3, 2021

    @coolbutuseless
    Collaborator

    Note to self (or future code submitter) - geom_circle from {ggforce} is probably the ideal candidate for adaptation.

    https://cran.r-project.org/package=ggforce

  4. changed the title [-]Support for 'geom_circle()'[/-] [+]Support for `geom_circle()`[/+] on Apr 24, 2024
  5. trevorld commented on Apr 24, 2024

    @trevorld
    Owner

    Although we'd still welcome a PR that adds a geom_circle_pattern() to {ggpattern} in the future it may be possible to directly use pattern/gradient fills with ggforce::geom_circle(): thomasp85/ggforce#323

  6. changed the title [-]Support for `geom_circle()`[/-] [+]Support for `geom_point_pattern()`[/+] on Dec 11, 2024
  7. trevorld commented on Dec 11, 2024

    @trevorld
    Owner
    • I opened a PR in {ggforce} to allow pattern fills in geom_circle() but I checked and it doesn't really support this use case.
    • However I suspect in R 4.2+ (with a compatible graphics device) you could do this in {ggplot2} 3.5+ using geom_point() with shape = 21 (the circle with separate fill) and a large enough size value and a relevant list of grid::pattern() fill values perhaps via gridpattern::patternFill("image").
  8. changed the title [-]Support for `geom_point_pattern()`[/-] [+]`geom_circle_pattern()`[/+] on Dec 11, 2024
  9. changed the title [-]`geom_circle_pattern()`[/-] [+]`geom_point_pattern()`[/+] on Nov 8, 2026
  10. self-assigned this
    on Nov 13, 2026
  11. trevorld commented on Nov 14, 2026

    @trevorld
    Owner

    Also closed by #167 . Currently we only do patterns for the "filled shapes" e.g. shape = 21 (filled circle---the default) through shape 25 (filled triangle point down). The other point shapes are passed through unaltered.

    library("ggplot2")
      library("ggpattern")
    
      images <- c(
        "R logo"  = system.file("img", "Rlogo.png", package = "png"),
        magpie    = system.file("img", "magpie.jpg", package = "ggpattern"),
        bug       = system.file("img", "bug.jpg", package = "ggpattern"),
        building  = system.file("images", "building.jpg", package = "magick"),
        ggplot2   = system.file("help", "figures", "logo.png", package = "ggplot2")
      )
      df <- data.frame(x = 1:5, y = c(2, 4, 3, 5, 1), image = names(images))
    
      ggplot(df, aes(x, y, pattern_filename = image)) +
        geom_point_pattern(pattern = "image", pattern_type = "expand",
                           size = 20, fill = "white", stroke = 1) +
        scale_pattern_filename_manual(values = images) +
        scale_x_continuous(expand = expansion(add = 0.6)) +
        scale_y_continuous(expand = expansion(add = 0.6))
    image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions