可以将透明度与PostScript / EPS一起使用吗? [英] Can transparency be used with PostScript/EPS?
问题描述
我正在尝试将R图另存为EPS文件,但是该图的以下部分存在问题-灰色透明多边形(透明黑色=灰色效果):
polygon(x.polygon,y.polygon.6,col =#00000022,border = NA)
当将图形另存为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射血分数(%),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)
轴(2,at = seq(0,70,10),标签= 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<-函数(x)sqrt(var(x,na.rm = TRUE)/ length(na.omit(x)))
avg< -c(平均值( initial_timepoint,na.rm = T),平均值(second_timepoint,na.rm = T),平均值(third_timepoint,na.rm = T),平均值(final_timepoint,na.rm = T))
err <-c (stderr(initial_timepoint),stderr(second_timepoint),stderr(third_timepoint),stde rr(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)
多边形(x.polygon,y.polygon.6,col =#00000022,border = NA)
线(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()
解决方案尽管EPS格式本身不支持半透明性,但仍然可以使用
cairo_ps()
来自动将半光栅化-透明区域及其分辨率,可以使用参数fallback_resolution
来控制:cairo_ps(文件= test.eps,一个文件=假,fallback_resolution = 600)
qplot(Sepal.Length,Petal.Length,data = iris,color = Species,size = Petal .width,alpha = I(0.7))
dev.off( )
然后所有非半透明区域都很好地保留为矢量图形。
或更短的话,您也可以使用:
ggsave( filename.eps, device = cairo_ps,fallback_resolution = 600)
或使用新的<$使用功能导出到eps c $ c> export 软件包,该软件包刚刚在CRAN上发布:
install.packages( export)
库(export)
graph2eps( filename.eps,fallback_resolution = 600)
该软件包还支持许多其他导出格式,包括Powerpoint(
graph2ppt
),请参见?graph2vector
,也保留了半透明...I am trying to save an R plot as an EPS file but I have a problem with the following component of the plot - the gray transparent polygon (transparent black = gray effect):
polygon(x.polygon, y.polygon.6, col="#00000022", border=NA)
This line of code works fine when saving the plot as PDF but not as EPS. Looks like EPS does not support transparency? What other choice would I have?
Here is the code for the full plot:
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()
解决方案Although the EPS format does not natively support semi-transparency, it is still possible to use
cairo_ps()
, that one automatically rasterizes semi-transparent areas, and the resolution at which it does this can be controlled with the argumentfallback_resolution
:cairo_ps(file = "test.eps", onefile = FALSE, fallback_resolution = 600) qplot(Sepal.Length, Petal.Length, data = iris, color = Species, size = Petal.Width, alpha = I(0.7)) dev.off()
All the non-semi-transparent areas then nicely stay as vector graphics.
Or even shorter you can also use :
ggsave("filename.eps", device=cairo_ps, fallback_resolution = 600)
Or use the functions to export to eps using the new
export
package, which just came out on CRAN :install.packages("export") library(export) graph2eps("filename.eps", fallback_resolution = 600)
That package also supports a number of other export formats, including Powerpoint (
graph2ppt
), see?graph2vector
, which also retains semi-transparency...这篇关于可以将透明度与PostScript / EPS一起使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!