Skip to content

Make a ggplot 0,0 XY coordinate to coincide with a specific point of a background image #25

@paleomariomm

Description

@paleomariomm

I have recently came across your package, I am a little excited and skeptical at the same time. I am developing a new package in R and need to solve one important issue. Maybe your knowledge can help me and maybe cooperate in the future. I am going to explain my issue:

I would like to combine two relevant things:

  • A ggplot plot.
  • And a background image.

However, I would like to do so by taking into consideration a particular point of the background image. I would like a specific point in the background image to be the XY coordinate (0,0) of the ggplot.

Data

Let's start with some data to illustrate what I want. Let's load iris dataset.

data(iris)

We create the ggplot()

Now, let's create this scatterplot with the petal measurements.

g <- ggplot(iris, aes(x= Petal.Length, y = Petal.Width)) + 
  geom_point() +
  xlim(0,7) + ylim(0,2.5) +
  theme_minimal()
print(g)

enter image description here

Background image

This is the background image I would like to implement.

enter image description here

Selecting the XY (0,0) coordinate in the image

This is the point of the background image where I would like to anchor the XY (0,0) of the ggplot.

enter image description here

Expected output

The expected output must be anchoring the XY 0,0 of the ggplot to the selected point of the background image, no matter the size of the image.

It would be something like this:

enter image description here

How can I do it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions