Data for the plot_pxg()

36 views
Skip to first unread message

Saikat Bandyopadhyay

unread,
Oct 3, 2024, 9:58:51 AM10/3/24
to R/qtl2 discussion
I am trying to extract the data that is being plotted by the plot_pxg() to crate the plot with ggplot instead of the R base.

What is the best way to go about this?


So far I have a function like this but its incomplete:

```
plot_pxg_ggplot <- function(pheno_name, loci){
  # get the peak data related to the loci
  loci_pheno_peak <- qtl_peak_loci %>% filter(
    lodcolumn==pheno_name & manual_annotation_locus== loci)
  # get the loci related marker data
  loci_data <- loci_marker_data[[loci]]
  # convert the data into long format
  loci_data_long <- loci_data %>%
    pivot_longer(
      4:(ncol(loci_data)-1),
      names_to ="lodcolumn",
      values_to = "LOD") %>%
    filter(lodcolumn == pheno_name)

  # get the chromosome where the loci is located
  chr <- unique(loci_data_long$chr)
  # pheno data for the specified phenotype
  pheno_data  <- as.numeric(pheno[,pheno_name])
  pheno_data_inverse_normal <- inverse_normal_transform(pheno_data)
  names(pheno_data_inverse_normal) <- rownames(cross_basic$pheno)
  # subset the allele probability data to only include the markers in the loci

  # get the genotypes for the specified
  genotype <- maxmarg(
    probs = pr,
    map = cross_basic$pmap,
    chr = chr,
    pos = loci_pheno_peak$pos
    )

  geno <- factor(genotype)
  return(geno)

}
```
Thank you.

Karl Broman

unread,
Oct 3, 2024, 10:03:36 AM10/3/24
to R/qtl2 discussion
I'd recommend using the ggplot_pxg function in the qtl2ggplot package.
(Brian Yandell's companion package that implements all of the plotting functions but with ggplot rather than base graphics.)

karl

Saikat Bandyopadhyay

unread,
Oct 3, 2024, 1:07:37 PM10/3/24
to R/qtl2 discussion

Dear Dr Karl, 

I am afraid the ggplot_pxg does not provide the level of customizability I was hoping for and it seems the ggplot_pxg function clusters more individuals in the 'NA' genotype, which is not the case when I use plot_pxg. 

Is there a way, to extract the data as a data frame that I can plot myself?

Thank you so much

Karl Broman

unread,
Oct 3, 2024, 1:17:16 PM10/3/24
to R/qtl2 discussion
I don't quite understand what you're looking for, as the input to these functions (plot_pxg and ggplot_pxg) are a vector of genotypes and a vector of phenotype values, which is presumably the data that you want, for making your own plot.

karl

Saikat Bandyopadhyay

unread,
Oct 3, 2024, 1:52:44 PM10/3/24
to R/qtl2 discussion
Hi Dr Karl,

I figured it out.

I was looking to create a data frame where one of the columns is the genotype and the rest are phenotypes. I was not using the option return_char = TRUE in the maxmarg(), which is why I got confused. But I have the required data structure now.

Thank you very much for your responses, and I am sorry for the error on my part.

Best,
Saikat
Reply all
Reply to author
Forward
0 new messages