我正在尝试使用cowplot包draw_image()
功能。我已经设法在图表中获取图像作为示例。
我无法弄清楚 xy 位置是如何工作的,我必须不断输入随机数,直到看到图像。
require(ggplot2) #required packages
require(cowplot)
require(magick)
p1 <- qplot(Sepal.Length, Sepal.Width, data = iris)
ggdraw(p1) +
draw_image(
"https://upload.wikimedia.org/wikipedia/en/7/77/EricCartman.png",
y = 0.2,
scale = 0.5
)
任何人都可以建议他们的运作规模如何?它看起来确实与图表的比例不同。
它位于绘图的坐标中。可能让您感到困惑的一点是ggdraw()
正在建立一个新的坐标系,x 和 y 都从 0 到 1。如果你想在绘图坐标中绘制图像,则无需使用ggdraw()
。只需添加draw_plot()
直接进入剧情。
library(ggplot2)
library(cowplot)
theme_set(theme_bw())
p1 <- qplot(Sepal.Length, Sepal.Width, data = iris)
# ggdraw() sets up a new coordinate system running from 0 to 1. This
# allows you to place an image on top of the plot.
ggdraw(p1) +
draw_image("https://upload.wikimedia.org/wikipedia/en/7/77/EricCartman.png")
# if you want to draw the image into the plot, don't use ggdraw()
p1 + draw_image(
"https://upload.wikimedia.org/wikipedia/en/7/77/EricCartman.png",
x = 5, y = 2.5, width = 2, height = 1.5
)
Created on 2018-12-19 by the reprex package https://reprex.tidyverse.org (v0.2.1)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)