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

标签 r image plot

我想将 4-氨基苯甲酸的分子结构添加到我在 R 中的图中。该图显示了上述分子的红外光谱。有没有办法使用 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)

可以找到 .asc 文件 here .
我希望分子位于左下角,因为可用空间最大。

图像缩小了 85%:

enter image description here

最佳答案

您可以使用 png 添加图像文件和 grid包:

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是考虑原始尺寸的比例。

关于r - 如何使用 SMILES 或图像将分子结构添加到 R 中的绘图中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29662161/

相关文章:

r - R 是否区分字符向量和字符串?

r - 向树添加信息 - Rpart

javascript - 将多个图像下载到 1 个 zip 文件中

python - 有没有适用于 Python 3.0 的图形/绘图/类似库?

matlab - 传奇;键/颜色之前的文本/描述?

r - 基于 R 中的分组变量创建序列

wordpress - 我想在分享我的网站链接时添加图片

JQuery 第一次没有将背景图片设置为 div

python - x 轴上的刻度标签不对称 (Matplotlib)

R编程: Level of allowed recursion depth differs when calling a local helper function