我必须将使用 pROC 包生成的图形提交给需要可编辑图形的期刊(特别是 .svg 或 .ai 格式)。到目前为止,我只是右键单击生成的图形并将其另存为 .png。不幸的是,这对期刊来说不起作用。这是我的代码:
library(pROC)
par(pty="s")
r_lda = roc(crs$CRS, crs$tbscore_corr_lda_inv_crs)
r_cf1 = roc(crs$CRS, crs$cf1_inv)
r_cf3 = roc(crs$CRS, crs$cf3_inv)
r_gbp5 = roc(crs$CRS, crs$gbp5_inv)
r_dusp3 = roc(crs$CRS, crs$dusp3_inv)
multiple <- plot.roc(r_lda, print.auc=TRUE, auc.polygon=TRUE, auc.polygon.col = "#FFEBEE",print.thres=FALSE,
col=pal_pro[1], print.auc.y=0.50, print.auc.x=0.40, xlim = c(1.1,0))
multiple <- plot.roc(r_cf1, print.auc=TRUE, auc.polygon=FALSE,col=pal_pro[2], add=TRUE, print.auc.y=0.40, print.auc.x=0.40, xlim = c(1.2,0), ylim = c(0,1.2))
multiple <- plot.roc(r_gbp5, print.auc=TRUE, auc.polygon=FALSE,col=pal_pro[3], add=TRUE, print.auc.y=0.30, print.auc.x=0.40, xlim = c(1.2,0), ylim = c(0,1.2))
multiple <- plot.roc(r_dusp3, print.auc=TRUE, auc.polygon=FALSE,col=pal_pro[4], add=TRUE, print.auc.y=0.20, print.auc.x=0.40, xlim = c(1.2,0), ylim = c(0,1.2))
legend("bottom",
legend=c("TB score", "KLF2", "GBP5", "DUSP3"),
col=pal_pro,
lwd=6, cex =0.5, xpd = TRUE, horiz = TRUE)
text(0.2, 0.65, "TB score",col=pal_pro[1], font=2)
text(0.5, 0.45, "KLF2",col=pal_pro[2])
text(0.8, 0.7, "GBP5",col=pal_pro[3])
text(0.55, 0.9, "DUSP3",col=pal_pro[4])
您能否提供一些有关如何将其保存为可编辑格式的建议?
我尝试使用指定了 device = "svg" 的 ggsave() 但它返回以下错误:
"Error in UseMethod("grid.draw") :
no applicable method for 'grid.draw' applied to an object of class "roc""
除此之外,其他解决方案要求我更改情节本身,但目前我无法做到。
使用
svglite
包将绘图写入 svg
文件。例如:
# Make some toy data
dat1 <- data.frame(x=rep(c(0,1),10), y=rnorm(20))
# Estimate a ROC
roc1 <- roc(dat1$x,dat1$y)
# Start the SVG device
svglite::svglite("rocTest.svg")
# Plot and add a text label
plot(roc1)
text(0.5,0.5,"Hi!")
# Close the device
dev.off()
注意
svglite
创建比常规 R svg
设备更好的可编辑 svg 文件。