绘制R中的质谱

时间:2016-09-26 02:01:36

标签: r plot

我希望在R中绘制不同样品质谱的三维叠加,非常类似于下图:(https://www.researchgate.net/publication/7662272/figure/fig1/AS:280563387781122@1443902932685/Figure-4-3D-overlay-zoom-plot-of-mass-spectra-of-a-serum-sample-from-one-person.png

我一直在尝试使用诸如'plot3D'之类的软件包,但最终的情节看起来并不像。是否有任何替代包可以产生与链接中相似/相同的情节?

1 个答案:

答案 0 :(得分:1)

我建议rgl包。

例;
library(rgl)

# example data
df <- cbind(expand.grid(x = 1:20, y = c(1,2,4,5)), 
            z = c(dnorm(1:20, 18), dnorm(1:20, 14), dnorm(1:20, 6), dnorm(1:20, 2)))

open3d()
plot3d(df, type="n", axes=F, ylab="", ylim=c(0.5, 5.5), zlim = c(0, 1))  # a draft
axes3d(edge="bbox", xat=-10, yat=-10, zat=-10)  # make a piece of box
axes3d(c("x", "z"))                                       # x and z axis
axis3d("y+-", at = c(1,2,4,5), label = c("t = 5", "t = 4", "t = 15", "t = 20"))  # y axis
for(i in c(1,2,4,5)) lines3d(df[df$y == i,], col=i+1)
text3d(5, 3, 0, "test", font=2)

附加示例;

library(rgl); library(dplyr)

# example data
df <- cbind(expand.grid(x = 1:20, y = c(1,2,4,5)), 
            z = c(dnorm(1:20, 18), dnorm(1:20, 14), dnorm(1:20, 6), dnorm(1:20, 2)))
df2 <- df %>% mutate(z = jitter(z) + 0.1)

open3d()       # type = "h" draw segments from z = 0. If you want another value for `from`, `segments3d()` achieves it.
plot3d(df2, type="h", axes=F, ylab="", ylim=c(0.5, 5.5), col="gray30", zlim=c(0, 1), lwd=3)
axes3d(edge="bbox", xat=-10, yat=-10, zat=-10)            # make a piece of box
axes3d(c("x", "z"))                                       # x and z axis
axis3d("y+-", at = c(1,2,4,5), label = c("t = 5", "t = 4", "t = 15", "t = 20"))  # y axis
for(i in c(1,2,4,5)) lines3d(df2[df2$y == i,], col=i+1, lwd=2)
text3d(5, 3, 0.05, "test", font=2)

enter image description here