knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  warning = FALSE,
  message = TRUE,
  out.width = "100%"
)

Data preparation

library(massstat)
library(magrittr)
library(dplyr)

data("liver_aging_pos")
liver_aging_pos

qc_id <-
  liver_aging_pos %>%
  activate_mass_dataset(what = "sample_info") %>%
  dplyr::filter(group == "QC") %>%
  dplyr::pull(sample_id)

object <-
  mutate_rsd(liver_aging_pos, according_to_samples = qc_id)

###only remain the features with rt > 100, mz > 150 and rsd < 30
object <-
  object %>%
  activate_mass_dataset(what = "variable_info") %>%
  dplyr::filter(rt > 100) %>%
  dplyr::filter(mz > 150) %>%
  dplyr::filter(rsd < 30)

##only remain the week 24 samples
object <-
  object %>%
  activate_mass_dataset(what = "sample_info") %>%
  dplyr::filter(group == "24W")

dim(object)

object <-
  object %>%
  `+`(1) %>%
  log(10) %>%
  scale_data(method = "auto")

Correlation network

graph_data <-
  convert_mass_dataset2graph(
    object = object,
    margin = "variable",
    cor_method = "spearman",
    p_adjust_cutoff = 1,
    p_value_cutoff = 0.0001,
    pos_cor_cutoff = 0.7,
    neg_cor_cutoff = -0.7
  )

graph_data
library(ggraph)
extrafont::loadfonts()
ggraph(graph = graph_data, layout = "kk") +
  geom_edge_fan(aes(color = correlation,
                    width = -log(p_value, 10)),
                show.legend = TRUE) +
  geom_node_point(aes(size = mz)) +
  theme_graph()

ggraph(graph = graph_data, layout = "fr") +
  geom_edge_fan(aes(color = correlation,
                    width = -log(p_value, 10)),
                show.legend = TRUE) +
  geom_node_point(aes(size = mz)) +
  theme_graph()

Session information

sessionInfo()


jaspershen/massstat documentation built on March 14, 2024, 7:02 p.m.