Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default aes // x and y labels #7

Open
sinarueeger opened this issue Nov 23, 2018 · 3 comments
Open

Default aes // x and y labels #7

sinarueeger opened this issue Nov 23, 2018 · 3 comments
Labels
qqplot this issue is related to stat_qqplot function

Comments

@sinarueeger
Copy link
Owner

sinarueeger commented Nov 23, 2018

If observed=P, then xlab and ylab should be:

xlab(expression(Expected ~ ~-log[10](italic(P)))) +
ylab(expression(Observed ~ ~-log[10](italic(P))))
  
@sinarueeger sinarueeger added the qqplot this issue is related to stat_qqplot function label Nov 23, 2018
@sinarueeger
Copy link
Owner Author

sinarueeger commented May 14, 2019

The default aes are for the geom_gwas_qq_{hex|}are y.

Problem
After plotting, the x-label is expected, the y-label whatever was passed onto y.
But we want -log10(expected) and -log10(P).

See also
See #47 (comment)

See also #2: the default aes to pass onto geom_qq is sample. And once plotted - the plot gets an x-axis theoretical (see below).

library(ggGWAS)
library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 3.5.2
set.seed(3)
df <- data.frame(P = runif(1000))

ggplot(df, aes(sample = P)) +
  stat_qq(distribution = stats::qunif) +
  scale_x_continuous(trans = "mlog10") +
  scale_y_continuous(trans = "mlog10")

Created on 2019-05-14 by the reprex package (v0.2.1)

This is part of the behaviour I would like to have for both geom_gwas_qq and geom_gwas_qq_hex.

@sinarueeger sinarueeger changed the title Automatic x and y labels Default aes // x and y labels (both kinda related) May 14, 2019
@sinarueeger sinarueeger changed the title Default aes // x and y labels (both kinda related) Default aes // x and y labels May 14, 2019
@sinarueeger
Copy link
Owner Author

sinarueeger commented May 14, 2019

So stat_qq has a desirable behaviour. This is what has been implemented before in geom_gwas_qq. However - this won't work on the hex version of qq.

StatQq <- ggproto("StatQq", Stat,
  default_aes = aes(y = stat(sample), x = stat(theoretical)), #########<<<< ADD THIS

  required_aes = c("sample"), #########<<<< ADD THIS

  compute_group = function(data, scales, quantiles = NULL,
                           distribution = stats::qnorm, dparams = list(),
                           na.rm = FALSE) {

    sample <- sort(data$sample)
    n <- length(sample)

    # Compute theoretical quantiles
    if (is.null(quantiles)) {
      quantiles <- stats::ppoints(n)
    } else {
      stopifnot(length(quantiles) == n)
    }

    theoretical <- do.call(distribution, c(list(p = quote(quantiles)), dparams))

    new_data_frame(list(sample = sample, theoretical = theoretical)) #########<<<< ADD THIS
  }
)

To get around the hex geom, I will try to use hexbin with a point geom.

@sinarueeger
Copy link
Owner Author

This could help: draw_panels and draw_labels could work

  # ,
  # draw_panels = function(data, panel_scales, coord) {
  #   ## Transform the data first
  #   coords <- coord$transform(data, panel_scales)
  #
  #   ## Let's print out the structure of the 'coords' object
  #   str(coords)
  #
  #   ## Construct a grid grob
  #   pointsGrob(
  #     x = coords$x,
  #     y = coords$y,
  #     pch = coords$shape
  #   )
  # },
  # draw_labels <- function(data, panel_scales, coord) {
  #  has something to do with gtable: https://ggplot2.tidyverse.org/reference/ggplot2-ggproto.html
  ## labels from qqman::qq()
  #  xlab(expression(Expected ~ ~-log[10](italic(p)))) +
  #  ylab(expression(Observed ~ ~-log[10](italic(p))))
  #     }

This was referenced May 14, 2019
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
qqplot this issue is related to stat_qqplot function
Projects
None yet
Development

No branches or pull requests

1 participant