Skip to content

Commit

Permalink
Support adjusting the font size of q-value labels in the factor detec…
Browse files Browse the repository at this point in the history
…tion result plot (#49)
  • Loading branch information
SpatLyu authored Feb 2, 2025
2 parents d5220fb + e2d1e31 commit e5d6063
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# gdverse 1.3-2

* Support adjusting the font size of q-value labels in the factor detection result plot (#49).

* Rename `gd_besttunidisc` as `gd_optunidisc` (#39).

* Specify that the `cores` parameter in all functions of the `gdverse` package currently supports
Expand Down
8 changes: 5 additions & 3 deletions R/geodetector.R
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,14 @@ print.ecological_detector = \(x, ...) {
#' @param alpha (optional) Confidence level. Default is `0.95`.
#' @param keep (optional) Whether to keep Q-value results for insignificant variables,
#' default is `TRUE`.
#' @param qlabelsize (optional) Set the font size of the q-value text labels in the plot.
#' @param ... (optional) Other arguments passed to `ggplot2::theme()`.
#'
#' @return A ggplot2 layer.
#' @export
#'
plot.factor_detector = \(x, slicenum = 2, alpha = 0.95, keep = TRUE, ...) {
plot.factor_detector = \(x, slicenum = 2, alpha = 0.95,
keep = TRUE, qlabelsize = 3.88, ...) {
g = x$factor %>%
dplyr::select(variable, qv = `Q-statistic`,pv = `P-value`) %>%
dplyr::filter(!is.na(qv)) %>%
Expand All @@ -429,10 +431,10 @@ plot.factor_detector = \(x, slicenum = 2, alpha = 0.95, keep = TRUE, ...) {
values = c("#DE3533","#808080")) +
ggplot2::geom_text(data = dplyr::slice(g, seq(1,slicenum)),
ggplot2::aes(label = qv_text), hjust = 1.25,
family = "serif", fontface = "bold") +
family = "serif", fontface = "bold", size = qlabelsize) +
ggplot2::geom_text(data = dplyr::slice(g, -seq(1,slicenum)),
ggplot2::aes(label = qv_text), hjust = -0.1,
family = "serif", fontface = "bold") +
family = "serif", fontface = "bold", size = qlabelsize) +
ggplot2::labs(x = "Q value", y = "") +
ggplot2::theme_bw() +
ggplot2::theme(panel.grid.major.y = ggplot2::element_blank(),
Expand Down
4 changes: 3 additions & 1 deletion man/plot.factor_detector.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e5d6063

Please sign in to comment.