drostlab / myTAI

Evolutionary Transcriptomics with R
https://drostlab.github.io/myTAI/
GNU General Public License v2.0
38 stars 16 forks source link

p-value in `PlotSignature()`as subtitle #16

Closed LotharukpongJS closed 1 year ago

LotharukpongJS commented 1 year ago

Is your feature request related to a problem? Please describe. The p values (e.g. p_flt) from the PlotSignature() function are added via ggplot2::annotate() and don't always fit the screen when making a small figure.

data(PhyloExpressionSetExample)
p <- PlotSignature(ExpressionSet = PhyloExpressionSetExample, permutations = 100)
p
Screenshot 2023-07-06 at 13 54 43

Describe the solution you'd like Perhaps the p-value can be passed as the subtitle for the plot. This will remove the issue of the text being cut off when making small figures. Here is an example implementation (without the preexisting p-value label).

p + ggplot2::labs(subtitle = ggplot2::ggplot_build(p)$data[[3]][["label"]])
# ggplot2::ggplot_build(p)$data[[3]][["label"]] extracts the annotation from the ggplot2 object.
Screenshot 2023-07-06 at 15 09 38

However, this removes the flexibility users might have when they want to customise the subtitle themselves. On the other hand, it also makes sense for the p-value to be presented in the subtitle. When the size is too big, the size of the subtitle can be changed.

p + ggplot2::labs(subtitle = ggplot2::ggplot_build(p)$data[[3]][["label"]]) + 
  ggplot2::theme(plot.subtitle = ggplot2::element_text(size=18, face="italic"))
Screenshot 2023-07-06 at 15 24 55

Whereas it is non-trivial to edit (or remove in the case above) annotations (ggplot2::annotate("text", ...)) post-facto. https://stackoverflow.com/questions/20083700/how-to-have-annotated-text-style-to-inherit-from-theme-set-options

(Let me know if otherwise)

Describe alternatives you've considered Move the coordinate of the annotation. However, this can also lead to a similar issue (1. the label may not fit the plot & 2. it is unclear [to me] how annotations can be modified post-facto).

Additional context Lines implicated in https://github.com/drostlab/myTAI/blob/master/R/PlotSignature.R

https://github.com/drostlab/myTAI/blob/e8c12b12de4b6b5ce07aaa046ed199c6277e3e41/R/PlotSignature.R#L295-L302

https://github.com/drostlab/myTAI/blob/e8c12b12de4b6b5ce07aaa046ed199c6277e3e41/R/PlotSignature.R#L310-L317

https://github.com/drostlab/myTAI/blob/e8c12b12de4b6b5ce07aaa046ed199c6277e3e41/R/PlotSignature.R#L338-L345

etc.

HajkD commented 1 year ago

Hi @LotharukpongJS

Sounds good to me to place the p-value into the legend title.

Feel free to send me a PR and I will merge it in!

With many thanks and very best wishes, Hajk