-
Notifications
You must be signed in to change notification settings - Fork 23
added tinyplot.data.frame method #613
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
Open
zeileis
wants to merge
5
commits into
main
Choose a base branch
from
data-frame-method
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+140
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9149657
added tinyplot.data.frame method
zeileis b7c5b54
Merge branch 'main' into data-frame-method
grantmcdermott 145c645
pairs-esque display in data.frame method for 3 or more variables
zeileis f4fb598
avoid using |> in examples
zeileis 3b0cc13
Merge branch 'main' into data-frame-method
grantmcdermott File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| #' tinyplot Method for Plotting Data Frames | ||
| #' | ||
| #' @description Convenience interface for visualizing data.frame objects | ||
| #' with tinyplot. | ||
| #' | ||
| #' @details This is a convenience function for plotting data frames with | ||
| #' or without a formula. The case with the formula mainly facilitates | ||
| #' using `tinyplot()` in combination with pipes. The case without | ||
| #' formula provides a quick way of plotting the variables in data frames, | ||
| #' either only one variable or a pair of variables, or all possible pairs | ||
| #' of variables. | ||
| #' | ||
| #' @param x an object of class `"data.frame"`. | ||
| #' @param formula a \code{\link[stats]{formula}} that is passed on to | ||
| #' \code{\link{tinyplot.formula}}. If `formula` is `NULL` a formula of | ||
| #' type `y ~ 1` or `y ~ x` is set up for 1- and 2-dimensional data frames, | ||
| #' respectively. For data frames with more than 2 variables the `facet = NULL` | ||
| #' case is not supported, yet, and currently leads to an error. | ||
| #' @param ... further arguments passed to `tinyplot`. | ||
| #' | ||
| #' @examples | ||
| #' tinytheme("clean2") | ||
| #' | ||
| #' ## using tinyplot() with data frames | ||
| #' tinyplot(cars) | ||
| #' tinyplot(iris, Sepal.Length ~ Petal.Width | Species) | ||
| #' | ||
| #' ## note that this also enables usage with pipes (in R >= 4.1.0) such as | ||
| #' ## cars |> tinyplot() | ||
| #' ## iris |> tinyplot(Sepal.Length ~ Petal.Width | Species) | ||
| #' | ||
| #' ## pairs-style display for more than 2 variables | ||
| #' ## (handling of axes and their labels will be improved in future versions) | ||
| #' tinyplot(iris) | ||
| #' | ||
| #' tinytheme() ## reset | ||
| #' | ||
| #' @importFrom stats reformulate | ||
| #' @export | ||
| tinyplot.data.frame = function (x, formula = NULL, ...) { | ||
| ## original call | ||
| cl = match.call() | ||
|
|
||
| ## update call for formula interface | ||
| names(cl)[names(cl) == "x"] = "data" | ||
| cl[[1L]] = quote(tinyplot::tinyplot) | ||
| if (is.null(formula)) cl$formula = . ~ . | ||
| id = which(names(cl) == "formula") | ||
| cl = as.call(as.list(cl)[c(1L, id, setdiff(2L:length(cl), id))]) | ||
|
|
||
| ## variables | ||
| nm = names(x) | ||
| n = length(nm) | ||
|
|
||
| if (is.null(formula) & n > 2L) { | ||
|
|
||
| ## 3d: pairs-esque | ||
| op = par(mfrow = c(n, n)) | ||
| for (j in 1L:n) { | ||
| for (i in 1L:n) { | ||
| cl_ij = cl | ||
| if (i == j) { | ||
| cl_ij$formula = reformulate("1", nm[i]) | ||
| cl_ij$xlab = "" | ||
| cl_ij$ylab = "" | ||
| cl_ij$main = nm[i] | ||
| } else { | ||
| cl_ij$formula = reformulate(nm[i], nm[j]) | ||
| if (i > 1L) cl_ij$ylab = "" | ||
| if (j < n) cl_ij$xlab = "" | ||
| } | ||
| eval.parent(cl_ij) | ||
| } | ||
| } | ||
| par(op) | ||
|
|
||
| } else { | ||
|
|
||
| ## default formula | ||
| ## 1d: y ~ 1 | ||
| ## 2d: y ~ x | ||
| if (is.null(formula)) { | ||
| cl$formula = if (length(nm) < 2L) reformulate("1", nm) else reformulate(nm[1L], nm[2L]) | ||
| } | ||
|
|
||
| ## evaluate updated call | ||
| eval.parent(cl) | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.