我想从网上阅读一张图片.例如
http://api.altmetric.com/donut/502878_64x64.png
并将其插入a的右上角 ggplot
df <- data.frame(x=1:10, y=sample(1:100,10))
# a fake plot to try it on.
ggplot(df, aes(x,y)) + geom_point(size = 2)
Run Code Online (Sandbox Code Playgroud)
我该怎么做?
mne*_*nel 20
你正在寻找annotation_raster和readPNG
mypngfile <- download.file('http://api.altmetric.com/donut/502878_64x64.png', destfile = 'mypng.png', mode = 'wb')
library(png)
mypng <- readPNG('mypng.png')
p <- qplot(mpg, wt, data = mtcars) + theme_bw()
p + annotation_raster(mypng, ymin = 4.5,ymax= 5,xmin = 30,xmax = 35) +
geom_point()
Run Code Online (Sandbox Code Playgroud)

正确的解决方案是:
# This was one of my issues, reading a png from the web
my_image <- readPNG(getURLContent('http://path.to/image.png'))
p1 + annotation_raster(my_image, ymin = 4,ymax= 5,xmin = 30,xmax = 40)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6252 次 |
| 最近记录: |