我已经尝试按照已经给出的答案将图像添加到绘图中,但是它们在使用时不起作用coord_polar()
# install.packages("RCurl", dependencies = TRUE)
library(RCurl)
myurl <- "http://vignette2.wikia.nocookie.net/micronations/images/5/50/German_flag.png"
# install.packages("png", dependencies = TRUE)
library(png)
img <- readPNG(getURLContent(myurl))
# install.packages("ggplot2", dependencies = TRUE)
library(ggplot2)
ger <- grid::rasterGrob(img, interpolate=TRUE)
## works, adds the image to the plot
ggplot(mtcars, aes(x=mpg, y= cyl)) + geom_line() + annotation_custom(ger, 10, 15, 5)
## doesn't work
ggplot(mtcars, aes(x=mpg, y= cyl)) + geom_line() + annotation_custom(ger) + coord_polar()
> Error: annotation_custom only works with Cartesian coordinates
Run Code Online (Sandbox Code Playgroud)
理想情况下,我希望能够将标志图像定位在极坐标图的中心,并沿着 y 轴定位另一个图像。
无论如何要添加图像?它可以原样,无需转换。
我正在使用ggplot2 …