将图像大小调整为 ggplot2 网格
adjust image size to ggplot2 grid
我需要绘制图像。我遇到的问题是我的 PNG 图像无法适应网格:
library(webshot)
library(png)
webshot("http://www.doctormetrics.com/","doctor.png")
img <- readPNG("doctor.png")
dim(img)
x11()
g <- rasterGrob(img, interpolate=TRUE)
qplot(1:2, 1:2, geom="blank") +
annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) +
geom_point()
你可以
library(webshot)
library(png)
library(ggplot2)
library(grid)
webshot("http://www.doctormetrics.com/",tf<-tempfile(fileext = ".png"))
img <- readPNG(tf)
g <- rasterGrob(img, interpolate=TRUE, height = 1, width = 1)
ggplot() +
annotation_custom(g, xmin=1, xmax=2, ymin=1, ymax=2) +
geom_point(aes(x,y), data.frame(x=1:2, y=1:2)) +
coord_fixed(ratio = nrow(img)/ncol(img))
我需要绘制图像。我遇到的问题是我的 PNG 图像无法适应网格:
library(webshot)
library(png)
webshot("http://www.doctormetrics.com/","doctor.png")
img <- readPNG("doctor.png")
dim(img)
x11()
g <- rasterGrob(img, interpolate=TRUE)
qplot(1:2, 1:2, geom="blank") +
annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) +
geom_point()
你可以
library(webshot)
library(png)
library(ggplot2)
library(grid)
webshot("http://www.doctormetrics.com/",tf<-tempfile(fileext = ".png"))
img <- readPNG(tf)
g <- rasterGrob(img, interpolate=TRUE, height = 1, width = 1)
ggplot() +
annotation_custom(g, xmin=1, xmax=2, ymin=1, ymax=2) +
geom_point(aes(x,y), data.frame(x=1:2, y=1:2)) +
coord_fixed(ratio = nrow(img)/ncol(img))