2016-09-26 7 views
0

Ich suche ein 3-D-Overlay der Massenspektren von verschiedenen Proben in R zu zeichnen, ähnlich wie die folgenden Abbildung :(https://www.researchgate.net/publication/7662272/figure/fig1/AS:[email protected]/Figure-4-3D-overlay-zoom-plot-of-mass-spectra-of-a-serum-sample-from-one-person.png)Plotten Massenspektren in R

Ich habe versucht, Pakete zu verwenden, wie zum Beispiel "plot3D", aber die endgültige Handlung sieht nicht so vorzeigbar aus. Gibt es alternative Pakete, die ein ähnliches/identisches Diagramm wie das in der Verknüpfung erzeugen können?

Antwort

1

Ich empfehle rgl Paket.

Beispiel;
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) 

zusätzliches Beispiel;

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

+0

das ist toll Dank! Um das hinzuzufügen, ist es möglich, das Skript so zu modifizieren, dass alle Werte in einem Liniendiagramm nicht durch einen Balkenplot dargestellt werden (wie das folgende Bild - nicht ganz sicher, ob es ein Barplot ist) per se https://www.researchgate.net/profile/Yangbing_Zhao/publication/238714854/figure/fig6/AS:[email protected]/FIG-4-Mass-spectra-of-ammonium-nitrate-NH4NO3-potassium-nitrat- KNO3-und-Kalium.png) – tolo9397

+0

@ tolo9397; OK, ich habe bearbeitet. – cuttlefish44