daattali / ggExtra

📊 Add marginal histograms to ggplot2, and more ggplot2 enhancements
http://daattali.com/shiny/ggExtra-ggMarginal-demo/
Other
383 stars 48 forks source link

Subtitle position changes based on presence or absence of title #99

Closed IndrajeetPatil closed 6 years ago

IndrajeetPatil commented 6 years ago

Hi,

I have a wrapper function around ggExtra::ggMarginal() in my package (it just adds results from statistical tests) and I noticed some unusual behavior with this function: It changes the position of the subtitle based on whether a title is present or not. Is this desired behavior? Is it possible to always have the subtitle on top of the marginal plots? Otherwise, at least in my view, the subtitle looks pretty cramped between the marginal distribution and the plot panel.

Here is a reprex:

# install.packages("devtools")
devtools::install_github("IndrajeetPatil/ggstatsplot")
#> Skipping install of 'ggstatsplot' from a github remote, the SHA1 (f801b442) has not changed since last install.
#>   Use `force = TRUE` to force installation

# without title
p1 <- ggstatsplot::ggscatterstats(data = iris,
                                  x = Sepal.Length,
                                  y = Sepal.Width)
#> Warning: This function doesn't return ggplot2 object. Thus, this plot is not further modifiable with ggplot2 commands.
#> 

# with title
p2 <- ggstatsplot::ggscatterstats(data = iris,
                                  x = Sepal.Length,
                                  y = Sepal.Width,
                                  title = "Dataset: Iris")
#> Warning: This function doesn't return ggplot2 object. Thus, this plot is not further modifiable with ggplot2 commands.
#> 

# plotting side-by-side to highlight the difference
cowplot::plot_grid(p1,
                   p2,
                   labels = c("(a)", "(b)"),
                   nrow = 1,
                   ncol = 2)

Created on 2018-03-11 by the reprex package (v0.2.0).

daattali commented 6 years ago

Hi Indrajeet,

I haven't looked through this issue yet, but could you please post a more isolated example, that only uses ggMarginal code and doesn't use your wrapper functions? It would be more indicative of a problem with ggmarginal if you can show a problem using only ggmarginal code


Dean Attali President & CEO AttaliTech Ltd http://AttaliTech.com http://attalitech.com

Want to improve your Shiny skills? Try my new interactive, online video course Shiny Case Studies https://www.datacamp.com/courses/building-web-applications-in-r-with-shiny-case-studies

On 11 March 2018 at 14:09, Indrajeet Patil notifications@github.com wrote:

Hi,

I have a wrapper function around ggExtra::ggMarginal() in my package (it just adds results from statistical tests) and I noticed some unusual behavior with this function: It changes the position of the subtitle based on whether a title is present or not. Is this desired behavior? Is it possible to always have the subtitle on top of the marginal plots? Otherwise, at least in my view, the subtitle looks pretty cramped between the marginal distribution and the plot panel.

Here is a reprex:

install.packages("devtools")devtools::install_github("IndrajeetPatil/ggstatsplot")#> Skipping install of 'ggstatsplot' from a github remote, the SHA1 (f801b442) has not changed since last install.#> Use force = TRUE to force installation

without titlep1 <- ggstatsplot::ggscatterstats(data = iris,

                              x = Sepal.Length,
                              y = Sepal.Width)#> Warning: This function doesn't return ggplot2 object. Thus, this plot is not further modifiable with ggplot2 commands.#>

with titlep2 <- ggstatsplot::ggscatterstats(data = iris,

                              x = Sepal.Length,
                              y = Sepal.Width,
                              title = "Dataset: Iris")#> Warning: This function doesn't return ggplot2 object. Thus, this plot is not further modifiable with ggplot2 commands.#>

plotting side-by-side to highlight the differencecowplot::plot_grid(p1,

               p2,
               labels = c("(a)", "(b)"),
               nrow = 1,
               ncol = 2)

https://camo.githubusercontent.com/1a9cf201c81c0239cb83946fb10650a3077b9ddf/68747470733a2f2f692e696d6775722e636f6d2f56376f42416f562e706e67

Created on 2018-03-11 by the reprex package http://reprex.tidyverse.org (v0.2.0).

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/daattali/ggExtra/issues/99, or mute the thread https://github.com/notifications/unsubscribe-auth/AA6IFDWPUZTSWHSYhZKlS2g8vqVWCrUhks5tdWhBgaJpZM4Slylb .

IndrajeetPatil commented 6 years ago

@daattali Sure!

Here is a minimal example with only the ggMarginal code. You can see that the same issue can be seen from this example.

library(ggExtra)
library(cowplot)
library(ggplot2)

# basic ggplot2 object
# without title
p1 <- ggExtra::ggMarginal(
  p = ggplot2::ggplot(
    data = iris,
    mapping = aes(x = Sepal.Length, y = Sepal.Width)
  ) +
    geom_point() +
    geom_smooth(method = "lm") +
    labs(subtitle = "subtitle")
)

# with title
p2 <- ggExtra::ggMarginal(
  p = ggplot2::ggplot(
    data = iris,
    mapping = aes(x = Sepal.Length, y = Sepal.Width)
  ) +
    geom_point() +
    geom_smooth(method = "lm") +
    labs(subtitle = "subtitle",
         title = "title") # only change
)

# plotting side-by-side to highlight the difference
cowplot::plot_grid(p1,
                   p2,
                   labels = c("(a)", "(b)"),
                   nrow = 1,
                   ncol = 2)

Created on 2018-03-11 by the reprex package (v0.2.0).

crew102 commented 6 years ago

Yeah, this behavior makes sense, given that we only test for whether a title is present (and not whether a subtitle is present).

https://github.com/daattali/ggExtra/blob/6521c1365e8b17cc40511faf7c3c04ac2d840273/R/ggMarginal.R#L124

Should be an easy fix for the next release.

IndrajeetPatil commented 6 years ago

Awesome, thanks! Looking forward to the next release.

daattali commented 6 years ago

@IndrajeetPatil this has been fixed