我是第一次在R中使用GggPatter包,我无法在我的情节中得到图像。下面是我的代码的一个简化版本:
x = seq(-1.5, 3.5, 0.1)
y = c( rep(1.0, 22), rep(0.2, 12), rep(0.7, 7), rep(1,10))
ref = data.frame(x = x, y = y)
library(dplyr)
library(ggplot2)
library(ggpattern)
coral = system.file("Coral", "coral.jpg", package="ggpattern")
p = ggplot(ref, aes(x = x, y = y))+
scale_y_reverse(lim = c(1, 0))+
theme_classic()+
geom_ribbon_pattern(aes(x = x, ymin = 1, ymax = y),
color = "darkblue",
fill = NA,
size = 1.5,
pattern = 'image',
pattern_type = 'squish',
pattern_filename = coral) +
geom_ribbon(aes(x = x, ymin = 0, ymax = y), fill = "lightblue")当我运行这段代码时,我所得到的就是:用缺少的图像填充来绘制

但是有了这个代码,我认为曲线下的白色区域应该用珊瑚图像填充。有人知道我做错了什么吗?我搜索了StackOverflow和GitHub,找不到答案。
发布于 2020-10-27 09:56:04
我认为这里的问题是在img模式的img文件夹中没有"coral.jpg“文件。
当我用文件夹中的一个图像编辑您的代码时,它工作得很好。
x = seq(-1.5, 3.5, 0.1)
y = c( rep(1.0, 22), rep(0.2, 12), rep(0.7, 7), rep(1,10))
ref = data.frame(x = x, y = y)
library(dplyr)
library(ggplot2)
library(ggpattern)
coral = system.file("img", "magpie.jpg", package="ggpattern")
p = ggplot(ref, aes(x = x, y = y))+
scale_y_reverse(lim = c(1, 0))+
theme_classic()+
geom_ribbon_pattern(aes(x = x, ymin = 1, ymax = y),
color = "darkblue",
fill = NA,
size = 1.5,
pattern = 'image',
pattern_type = 'squish',
pattern_filename = coral) +
geom_ribbon(aes(x = x, ymin = 0, ymax = y), fill = "lightblue")
p


https://stackoverflow.com/questions/64548088
复制相似问题