rcavalcante / annotatr

Package Homepage: http://bioconductor.org/packages/devel/bioc/html/annotatr.html Bug Reports: https://support.bioconductor.org/p/new/post/?tag_val=annotatr.
26 stars 8 forks source link

columns in plot_numerical #34

Closed gabyrech closed 4 years ago

gabyrech commented 4 years ago

Hi! I am trying to build a plot_numerical() with two categorical variables to facet over but I am getting 5 columns in the plot instead of 3 . My code is:

recomPlot <- plot_numerical(
  annotated_regions = te_annotated,
  x = 'Comeron',
  facet = c("annot.type", 'SFS_cat'),
  facet_order = list(c("dm6_genes_intergenic", "dm6_genes_1to5kb", "dm6_genes_3UTRs", "dm6_genes_5UTRs", "dm6_genes_introns", "dm6_genes_promoters", "dm6_genes_exons"),c('Rare','Polymorphic','Fixed')),
  bin_width = 0.5)

So, I would like my plot to show three columns (Rare','Polymorphic','Fixed) for each "annot.type". But instead I am getting 5 columns. Any way to change this? Thanks! Gabriel

rcavalcante commented 4 years ago

Hi Gabriel,

Could you please post the result of head(te_annotated) and the image that is produced? That'll help me piece together what might be happening.

Thanks, Raymond

gabyrech commented 4 years ago

Hi Raymond. Thanks for your reply. Here you go:

>head(te_annotated)
GRanges object with 6 ranges and 22 metadata columns:
      seqnames    ranges strand |               te_ref    frame    Class    Order SuperFamily   family
         <Rle> <IRanges>  <Rle> |             <factor> <factor> <factor> <factor>    <factor> <factor>
  [1]    chr2L    553854      - | 2L_553854_553854_412        .      RNA      LTR       Gypsy      412
  [2]    chr2L    553854      - | 2L_553854_553854_412        .      RNA      LTR       Gypsy      412
  [3]    chr2L    553854      - | 2L_553854_553854_412        .      RNA      LTR       Gypsy      412
  [4]    chr2L    553854      - | 2L_553854_553854_412        .      RNA      LTR       Gypsy      412
  [5]    chr2L    553854      - | 2L_553854_553854_412        .      RNA      LTR       Gypsy      412
  [6]    chr2L    553854      - | 2L_553854_553854_412        .      RNA      LTR       Gypsy      412
         inref   g_count  genomes        te_ids   te_len te_ratio     Comeron  FistonL RecomConclusion
      <factor> <integer> <factor>      <factor> <factor> <factor>   <numeric> <factor>        <factor>
  [1]       NO         1  TOM-007 TOM-007_1_412     7562    0.972 1.993676178    2.045             HRR
  [2]       NO         1  TOM-007 TOM-007_1_412     7562    0.972 1.993676178    2.045             HRR
  [3]       NO         1  TOM-007 TOM-007_1_412     7562    0.972 1.993676178    2.045             HRR
  [4]       NO         1  TOM-007 TOM-007_1_412     7562    0.972 1.993676178    2.045             HRR
  [5]       NO         1  TOM-007 TOM-007_1_412     7562    0.972 1.993676178    2.045             HRR
  [6]       NO         1  TOM-007 TOM-007_1_412     7562    0.972 1.993676178    2.045             HRR
        Filter   America    Europa     Other  SFS_cat chromosomeClean                 annot
      <factor> <integer> <integer> <integer> <factor>        <factor>             <GRanges>
  [1]     pass         0         1         0     Rare              2L chr2L:552924-553923:-
  [2]     pass         0         1         0     Rare              2L chr2L:553455-557454:-
  [3]     pass         0         1         0     Rare              2L chr2L:550503-554502:-
  [4]     pass         0         1         0     Rare              2L chr2L:553455-557454:-
  [5]     pass         0         1         0     Rare              2L chr2L:553742-554274:-
  [6]     pass         0         1         0     Rare              2L chr2L:553742-554274:-
  -------
  seqinfo: 5 sequences from an unspecified genome; no seqlengths

image

rcavalcante commented 4 years ago

Hi Gabrial,

I see what you mean now. You'd prefer that the facets be lined up in three columns for Rare, Polymorphic and Fixed. I think you should be able to do something like:

recomPlot = recomPlot + facet_wrap(V1 ~ V2, ncol = 3)

Since annotatr plot functions return the plots themselves, you can modify their styles after creating them. In this case, the V1 and V2 wouldn't have been obvious without looking in the source code. Sorry about that.

Let me know if that works?

Thanks, Raymond

gabyrech commented 4 years ago

Thanks Raymond, I am not sure if I should change V1 and V2 with any of my variables? I am getting this:

> recomPlot = recomPlot + facet_wrap(V1 ~ V2, ncol = 3)
> recomPlot
Error: At least one layer must contain all faceting variables: `V1`, `V2`.
* Plot is missing `V1`, `V2`
* Layer 1 is missing `V1`, `V2`
* Layer 2 is missing `V1`, `V2`
rcavalcante commented 4 years ago

Oh, perhaps I was trying to be too clever, does the following work?

recomPlot = recomPlot + facet_wrap(annot.type ~ SFS_cat, ncol = 3)
gabyrech commented 4 years ago

Great! That works! Thank so much for your help and congrats for annotatr, it is a a great tool and very useful! All the best, Gabriel

rcavalcante commented 4 years ago

Excellent, thanks for the feedback! I'll go ahead and close the issue.