R 在ggplot2的特定位置放置背景图像并进行测量

R 在ggplot2的特定位置放置背景图像并进行测量,r,ggplot2,png,R,Ggplot2,Png,到目前为止,我的问题对我来说很有挑战性。希望在你的帮助下我们能得到我所需要的 我想放置一个图像作为ggplot的背景 要复制的数据:需要两个对象:数据帧和图像 本问题末尾的数据 背景图像: 这是要作为背景放置的图像(molar.png): 到目前为止我所得到的。。。 我想: library(png) library(grid) library(ggplot2) img <- readPNG("images/molar.png") g <- rasterGrob(img, inte

到目前为止,我的问题对我来说很有挑战性。希望在你的帮助下我们能得到我所需要的

我想放置一个图像作为ggplot的背景

要复制的数据:需要两个对象:数据帧和图像

本问题末尾的数据

背景图像: 这是要作为背景放置的图像(
molar.png
):

到目前为止我所得到的。。。 我想:

library(png)
library(grid)
library(ggplot2)

img <- readPNG("images/molar.png")
g <- rasterGrob(img, interpolate = TRUE)

ggplot(df), aes(x = X, y = Y)) +
  coord_fixed(ratio = .75) +
  annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) +
  geom_point(alpha = .20, size = 1, shape = 19, color = "red") +
  stat_smooth(method = 'lm', formula = y ~ poly(x, 3)) +
  xlim(0, 100) + ylim(0, 100) +
  theme_minimal() +
  geom_hline(aes(yintercept = 0), color = "red", lty = 2) +
  geom_vline(aes(xintercept = 0), color = "red", lty = 2)
库(png)
图书馆(网格)
图书馆(GG2)

有趣的是,最近有人问了一个非常类似的问题。相关报道:目前还没有答案。做一件相当复杂的事情。查看相关的线程。我在考虑悬赏另一个问题,希望任何人都能回答。。。。