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

purrr::pmap not working with ggscatterstats when expression is used #38

Closed
IndrajeetPatil opened this issue Sep 1, 2018 · 6 comments
Closed
Labels
help wanted ❤️ Extra attention is needed

Comments

@IndrajeetPatil
Copy link
Owner

IndrajeetPatil commented Sep 1, 2018

The expression is not evaluated properly and so there are 0 rows in label_data and geom_label_repel fails.

library(tidyverse)

# for reproducibility
set.seed(123)

# let's split the dataframe and create a list by mpaa rating
mpaa_list <- ggstatsplot::movies_wide %>%
  base::split(x = ., f = .$mpaa, drop = TRUE)

# this created a list with 4 elements, one for each mpaa rating
# you can check the structure of the file for yourself
# str(mpaa_list)

# checking the length and names of each element
length(mpaa_list)
#> [1] 4
names(mpaa_list)
#> [1] "NC-17" "PG"    "PG-13" "R"

# running function on every element of this list note that if you want the same
# value for a given argument across all elements of the list, you need to
# specify it just once
plot_list1 <- purrr::pmap(
  .l = list(
    data = mpaa_list,
    x = "budget",
    y = "rating",
    xlab = "Budget (in millions of US dollars)",
    ylab = "Rating on IMDB",
    title = list(
      "MPAA Rating: NC-17",
      "MPAA Rating: PG",
      "MPAA Rating: PG-13",
      "MPAA Rating: R"
    ),
    label.var = list("title", "year", "votes", "genre"),
    label.expression = list(
      ("rating" > 8.5 &
        "budget" < 50),
      ("rating" > 8.5 &
        "budget" < 100),
      ("rating" > 8 & "budget" < 50),
      ("rating" > 9 & "budget" < 10)
    ),
    type = list("r", "np", "p", "np"),
    method = list(MASS::rlm, "lm", "lm", "lm"),
    marginal.type = list("histogram", "boxplot", "density", "violin"),
    centrality.para = "mean",
    xfill = list("#56B4E9", "#009E73", "#999999", "#0072B2"),
    yfill = list("#D55E00", "#CC79A7", "#F0E442", "#D55E00"),
    ggtheme = list(
      ggplot2::theme_grey(),
      ggplot2::theme_classic(),
      ggplot2::theme_light(),
      ggplot2::theme_minimal()
    ),
    messages = FALSE
  ),
  .f = ggstatsplot::ggscatterstats
)
#> Error: Aesthetics must be either length 1 or the same as the data (1): x, y

# combine plots
ggstatsplot::combine_plots(
  plotlist = plot_list,
  nrow = 4
)

Created on 2018-09-01 by the reprex package (v0.2.0.9000).

@ibecav
Copy link
Contributor

ibecav commented Sep 19, 2018

Just submitted a pull request.

@IndrajeetPatil
Copy link
Owner Author

IndrajeetPatil commented Sep 20, 2018

@ibecav Everything is looking great with ggscatterstats and grouped_ggscatterstats in the reprexes you posted. Can you also post a reprex here with the code in this issue (ggscatterstats + pmap), so that I can also check if it's displaying the results properly? I can merge the PR then.

@ibecav
Copy link
Contributor

ibecav commented Sep 20, 2018 via email

@IndrajeetPatil
Copy link
Owner Author

IndrajeetPatil commented Sep 20, 2018

Really sorry about that. You don't need to post reprex here anymore since they are in PR.

I am not sure which of your changes I overwrote. I think the vignette change happened because last night I was trying to reduce the size of vignettes and one of the way I could do that was by removing all pmap examples and make one vignette which will I set to eval = FALSE. I think that was the change that conflicted with your change. Because now it can no longer the pmap example in the ggscatterstats vignette. Sorry for making that change, but I thought you were making changes only to R files so I didn't touch them.

@IndrajeetPatil
Copy link
Owner Author

Also, this is the first time someone is making PRs to this repo and I am not sure how some of these things, so I am doing some mistakes. Apologies and I really appreciate your patience.

@ibecav
Copy link
Contributor

ibecav commented Sep 20, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted ❤️ Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants