如何使用SMILES或图像将分子结构添加到R中的图中?

时间:2015-04-15 22:39:14

标签: r image plot

我想在我的R图中添加4-氨基苯甲酸的分子结构。该图显示了所述分子的红外光谱。有没有办法使用SMILES代码添加O=C(O)c1ccc(N)cc1代码,或者我可以将其添加为图片,可以找到here(在底部编辑)。我写了以下脚本:

par(family="mono", font.axis=1)
data <- read.table("D13-4-aminobenzoic_acid.asc")
x <- data[,1]
y <- data[,2]
x1 <- x[rev(order(x))] # reverse order x

plot(x1,y, type="n", xlim=rev(range(x)),  
     axes=FALSE,
     xlab=expression(paste("Wavelength [", cm^-1,"]")),
     ylab="Transmittance [%]"
     )

lines(x1, y, col="firebrick")

axis(1, at=seq(500,4000,250))
axis(2, at=seq(40,100,10), xpd=T)

可以找到。{s}文件here。 我希望分子位于左下角,因为有最多的空间。

图片缩小了85%:<​​/ p>

enter image description here

1 个答案:

答案 0 :(得分:2)

您可以使用pnggrid包添加图片文件:

library(png)
library(grid)
img <- readPNG("img.png")
grid.raster(img, x=.15, y=.25, width=.3, hjust=0, vjust=0)

enter image description here

查看?grid.raster以了解该函数的其他参数。 xy可能难以优化,请注意widthheight是考虑原始大小的比例。