本文介绍了如何将图像叠加到ggplot上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想从网上读取图片。例如 http://api.altmetric.com/donut/502878_64x64.png 并将其插入 ggplot 的右上方, df #一个假的情节来试试它。 ggplot(df,aes(x,y))+ geom_point(size = 2) 我该怎么做? 和 readPNG mypngfile mypng< - readPNG('mypng。 png') p p + annotation_raster(mypng,ymin = 4.5,ymax = 5,xmin = 30,xmax = 35)+ geom_point() 这些新功能(以及更多示例) a href =http://cloud.github.com/downloads/hadley/ggplot2/guide-col.pdf =noreferrer> here I'd like to read an image from the web. e.g.http://api.altmetric.com/donut/502878_64x64.pngand insert it into the top right of a ggplotdf <- 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)How would I do this? 解决方案 You are looking for annotation_raster and readPNGmypngfile <- 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()These new features (and more examples) are described here 这篇关于如何将图像叠加到ggplot上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 02:53