如何在单个文件的单独页面中绘制SVG图[R]?

时间:2012-01-18 07:03:56

标签: r svg plot

如何将两个地块分成不同的页面?

命令onefile用于此目的,但不知何故,以下代码仅绘制了两个图中的最后一个。

这里有什么遗漏?

library(RSVGTipsDevice)

devSVGTips("svgplot9.svg", toolTipMode=1,onefile=TRUE,
title="SVG example plot 9: line and point types")
plot(c(0,20),c(0,5), type="n", xlab="x", ylab="y",
main="Example SVG plot with different line and point types")
for (i in 0:16) {
lines(i+(0:4), (1:5), col=max(i,1), pch=i, lty=i, type="b")
text(i, 0.5, lab=as.character(i), cex=2^(abs((i-8)/4)-1))
}


devSVGTips("svgplot9.svg", toolTipMode=1, onefile=TRUE,
title="SVG example plot 10: line and point types")
plot(c(0,20),c(0,5), type="n", xlab="x", ylab="y",
main="Example SVG plot with different line and point types")
for (i in 0:16) {
lines(i+(0:4), (1:5), col=max(i,1), pch=i, lty=i, type="b")
text(i, 0.5, lab=as.character(i), cex=2^(abs((i-8)/4)-1))
}

dev.off()

1 个答案:

答案 0 :(得分:1)

您可能希望尝试单次调用devSVGTips(第二个删除正在编写的文件),使用onefile=TRUE(两个图重叠在一个页面上)或onefile=FALSE(这两个图位于同一个文件中,但描述它们的XML代码只是连接在一起:这可能不是有效的XML和/或可能需要进一步处理)。

# Same code as yours, indented, and with 
# a different title for the second plot to see the difference.
library(RSVGTipsDevice)

devSVGTips(
  "svgplot9.svg", toolTipMode=1,
  onefile=FALSE, # Try with TRUE (overlaid plots) or FALSE (separate plots)
  title="SVG example plot 9: line and point types"
)
plot(
  c(0,20),c(0,5), type="n", xlab="x", ylab="y",
  main="Example SVG plot with different line and point types"
)
for (i in 0:16) {
  lines(i+(0:4), (1:5), col=max(i,1), pch=i, lty=i, type="b")
  text(i, 0.5, lab=as.character(i), cex=2^(abs((i-8)/4)-1))
}

#devSVGTips(
#  "svgplot9.svg", toolTipMode=1, onefile=TRUE,
#  title="SVG example plot 10: line and point types"
#)
plot(
  c(0,20),c(0,5), type="n", xlab="x", ylab="y",
  main="Example SVG plot with different line and point types (2)"
)
for (i in 0:16) {
  lines(i+(0:4), (1:5), col=max(i,1), pch=i, lty=i, type="b")
  text(i, 0.5, lab=as.character(i), cex=2^(abs((i-8)/4)-1))
}

dev.off()