GuangchuangYu / ggimage

:art: Use Images in ggplot2

Home Page:https://cran.r-project.org/package=ggimage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

paleomariomm opened this issue · comments

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?

This is an example of what I am really developing in my package. It is about human teeth. Not only a fixed point must be selected as the 0,0, but also a rescale of the image is mandatory. But this is for another question. Thanks in advance