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

Feature enhancement: allow changes to plots #60

Open
Ales-G opened this issue May 20, 2022 · 2 comments
Open

Feature enhancement: allow changes to plots #60

Ales-G opened this issue May 20, 2022 · 2 comments

Comments

@Ales-G
Copy link

Ales-G commented May 20, 2022

Hello,
I love the function makeDataReport and I use it often in my work.
One thing that I would really love is the possibility of making changes to the baseline ggplots.
For instance, when I have a character vector I often end up with bar plots that are difficult to read, as in the example below.

Screenshot 2022-05-20 at 13 01 24

Having the possibility to do the histogram on the y axis (simply replace aes(x=var) with aes(y=var) in ggplot) would really improve a lot the quality of the reports.

Is this something you are planning to include?

thanks a lot

@annennenne
Copy link
Collaborator

Thank you for reaching out!

This can easily be done, and we have provided a guideline for how to add such custom extensions to the built-in dataReporter tools in this vignette: https://cran.r-project.org/web/packages/dataReporter/vignettes/extending_dataReporter.html

Here's a minimal example of how it may be achieved (following the structure of the prettierHist()-example from the vignette):

library(dataReporter)

#Define helper function that does actual plotting
flippedBarplotHelper <- function(v, vnam) {
  p <- ggplot(data.frame(v = v), aes(x = v)) + 
    geom_bar() +
    coord_flip() #flip axes

  p
}

#define visualFunction-style flippedBarplot() function:
flippedBarplot <- function(v, vnam, doEval = TRUE) {
  #define the call
  thisCall <- call("flippedBarplotHelper", v = v, vnam = vnam)
  
  #evaluate or deparse
  if (doEval) {
    return(eval(thisCall))
  } else return(deparse(thisCall))
}

#Make it a proper visualFunction:
flippedBarplot <- visualFunction(flippedBarplot, 
                               description = "ggplot2 barplot with flipped axes",
                               classes = c("character", "factor"))

#Make dataReport using this new visualFunction for factor variables:
makeDataReport(toyData, visuals = setVisuals(factor = "flippedBarplot"))

Note that the function will also be visible in the allVisualFunctions() overview.

We'll think about adding this to the package when we do the next big update. But until then, the solution above should work.

@annennenne
Copy link
Collaborator

Oh, and I forgot to mention that the package has been renamed to dataReporter (see https://github.com/ekstroem/dataReporter/). So the dataMaid package is no longer being maintained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants