相关疑难解决方法(0)

尝试将图像添加到极坐标图会给出“错误:annotation_custom 仅适用于笛卡尔坐标”

我已经尝试按照已经给出答案将图像添加到绘图中,但是它们在使用时不起作用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 …

r ggplot2

3
推荐指数
1
解决办法
2373
查看次数

标签 统计

ggplot2 ×1

r ×1