如何创建显示特定离子的时间范围或确切时间的图表?

How do I create a graph that shows the time frames or exact times of specific ions?

我试图通过展示特定化合物及其保留时间来可视化我的初步数据。我想要达到的目标是能够在 x 轴上显示保留时间,在 y 轴上显示离子质量的图表。某些离子具有精确的保留时间或在分析仪器中洗脱的时间范围。

在下面的示例数据框中,QIon 是离子质量,RT 是时间范围(如果有),RT_Center 是准确的保留时间。一些化合物通过具有相同的质量但不同的保留时间而重叠,因此在图表上时间范围可能在相同的 y 轴上但在 x 轴上不同。如果您需要任何其他信息,请告诉我。

Compound       QIon   RT      RT_Center

Biphenyl       154    30-32
Fluorene       166            37.1
Dibenzofuran   168    31-34
Acenaphthene   154            34.14

我用我更习惯的方式编写了这段代码,但我可能也会在此处添加一些其他方式。

我加载了整个库 tidyverse,但我使用的是 ggplot2tidyr

library(tidyverse) # Or ggplot2 and tidyr

chem %>%
  separate(col = RT, sep = "-", into = c("Beginning", "End"), convert = TRUE) %>%
  ggplot(aes(y = QIon))+
  geom_point(aes(x = RT_Center))+
  geom_errorbar(aes(xmin = Beginning, xmax = End))+
  theme_minimal()

更多定制由您决定。

意思是这样的:首先,我将列 RT 分为开头和结尾。这样,我可以使用这些列来创建范围和点(检查 ?geom_errorbar 以查看其他 geoms)。

我相信这就是你的意思。由于既有范围也有单点,我认为同时使用两者是最合适的。如果这不是您想要的,请随时说出来。

这里有一个不使用管道的方法,如果它能让你更舒服的话:

library(ggplot2)

chem2 <- tidyr::separate(chem, col = RT, sep = "-", into = c("Beginning", "End"), convert = TRUE)
ggplot(chem2, aes(y = QIon))+
  geom_point(aes(x = RT_Center))+
  geom_errorbar(aes(xmin = Beginning, xmax = End))+
  theme_minimal()