16

Webから画像を読みたいです。例えば

http://api.altmetric.com/donut/502878_64x64.png

の右上に挿入します。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)

どうすればいいですか?

4

3 に答える 3

23

あなたが探しているannotation_rasterreadPNG

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()

ここに画像の説明を入力

これらの新機能 (およびその他の例) については、こちらで説明しています

于 2012-09-28T05:05:46.183 に答える
4

正しい解決策はこれでした:

# 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)
于 2012-09-28T05:09:24.153 に答える