相关疑难解决方法(0)

PostScript/EPS可以使用透明度吗?

我试图将R图保存为EPS文件,但我对图的以下组件有问题 - 灰色透明多边形(透明黑=灰色效果):

polygon(x.polygon, y.polygon.6, col="#00000022", border=NA)
Run Code Online (Sandbox Code Playgroud)

将这个代码保存为PDF而不是EPS时,这行代码可以正常工作.看起来EPS不支持透明度?我还有其他选择吗?

以下是完整情节的代码:

postscript(file="Figure.eps", width=5.5, height=5.5, onefile=F, horizontal=F)

ts(t(data.frame(initial_timepoint, second_timepoint, third_timepoint, final_timepoint)))->obj
obj[,-c(3,7)]->obj1
plot(obj1, plot.type="single", lwd=0.6, xaxs="i",yaxs="i",xlab="",ylab="LV ejection fraction (%)",xaxt='n',yaxt='n',ylim=c(0,70),col="black")
axis(1, at=c(1,2,3,4), labels=c("1","2","3","4"),cex.axis=1)
axis(2, at=seq(0,70,10), labels=c("0%","10%","20%","30%","40%","50%","60%","70%"),cex.axis=1, las=1)
abline(v=c(2,3),lwd=0.6,lty=2)

stderr <- function(x) sqrt(var(x,na.rm=TRUE)/length(na.omit(x)))
avg<-c(mean(initial_timepoint,na.rm=T), mean(second_timepoint,na.rm=T), mean(third_timepoint,na.rm=T), mean(final_timepoint,na.rm=T))
err<-c(stderr(initial_timepoint), stderr(second_timepoint), stderr(third_timepoint), stderr(final_timepoint))

my.count <- c(1,2,3,4)
my.count.rev <- c(4,3,2,1)
y.polygon.6 <- c((avg+err*1.96)[my.count],(avg-err*1.96)[my.count.rev])
x.polygon <- c(my.count, my.count.rev)
polygon(x.polygon, y.polygon.6, col="#00000022", border=NA)
lines(avg,col="black",lwd=0.8,lty=3)
lines((avg+err*1.96),lwd=0.8,lty=3)
lines((avg-err*1.96),lwd=0.8,lty=3)

dev.off()
Run Code Online (Sandbox Code Playgroud)

plot transparency r postscript

12
推荐指数
2
解决办法
6194
查看次数

是否可以使用 Cairo 图形设备通过 ggsave 创建 .eps 文件?

编辑:此页面提供代码:https : //www.andrewheiss.com/blog/2017/09/27/working-with-r-cairo-graphics-custom-fonts-and-ggplot/

ggsave("test_cario.eps", device=cairo_ps)

ggsave("test_cario.pdf", device=cairo_pdf)
Run Code Online (Sandbox Code Playgroud)

但是,我想知道命令来自哪里。它们未包含在官方文档 ( https://ggplot2.tidyverse.org/reference/ggsave.html )的可能设备列表中。并且,cairo_png 不存在;相反, type="cairo-png" 是必要的,例如:

ggsave("test_cairo.png", type = "cairo-png")
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么争论是一次device = ""又一次type = ""


我试过这样的代码

ggsave("model.eps", type = "cairo")
Run Code Online (Sandbox Code Playgroud)

或者

ggsave("model.eps", type = "cairo-ps")

或者

ggsave("model.eps", device = "cairo-ps")

但似乎没有任何效果。一般来说,是否可以使用 Cairo 图形设备通过 ggsave 创建 .eps 文件?如果是这样,如何?

r eps cairo ggplot2

6
推荐指数
1
解决办法
2934
查看次数

使用带有extrafont包的.eps图中的Arial时出错

我在R中使用ggplot2为出版物生成数字,其中所有数字都需要.eps格式,所有字体都需要是Arial.我一直在关注这个指南,以这样使用extrafont包.据我了解,该行loadfonts(device = "postscript")应该注册我导入的所有字体(包括Arial)和postscript设备.但是当我运行我的代码并尝试使用以下代码保存我的数字时:

ggplot() + geom_point(aes(x=xvar, y=yvar)) + theme_minimal(base_family = "Arial")
library(extrafont)
font_import()
loadfonts(device = "postscript")
ggsave(filename = "myfile.eps")
Run Code Online (Sandbox Code Playgroud)

我仍然收到此错误:

grid.Call中的错误(L_textBounds,as.graphicsAnnot(x $ label),x $ x,x $ y,:family'Arial'未包含在postscript()设备中

我错过了什么?

fonts r eps ggplot2

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

标签 统计

r ×3

eps ×2

ggplot2 ×2

cairo ×1

fonts ×1

plot ×1

postscript ×1

transparency ×1