Skip to content

Commit

Permalink
Merge pull request #99 from mattwarkentin/master
Browse files Browse the repository at this point in the history
updated stretch to factor x and y columns by default
  • Loading branch information
juliasilge authored Jun 25, 2020
2 parents 8cd34b1 + 42c9801 commit c6c6fe1
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 19 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Handle correlation of exactly zero or 1 in `network_plot()` (@s-scherrer, #89)

- Add `.order` argument to `rplot()` with options "default" and "alphabet" (@mattwarkentin, #99)

# corrr 0.4.2

- Updates to work with tibble 3.0.0 and dplyr 1.0.0
Expand Down
22 changes: 15 additions & 7 deletions R/cor_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ focus_if.cor_df <- function(x, .predicate, ..., mirror = FALSE) {
to_keep <- map_lgl(
x[, colnames(x) != "rowname"],
.predicate, ...
)
)

to_keep <- names(to_keep)[!is.na(to_keep) & to_keep]

Expand All @@ -114,7 +114,10 @@ rplot.cor_df <- function(rdf,
shape = 16,
colours = c("indianred2", "white", "skyblue1"),
print_cor = FALSE,
colors) {
colors,
.order = c("default", "alphabet")) {

.order <- match.arg(.order)

if (!missing(colors))
colours <- colors
Expand All @@ -127,6 +130,11 @@ rplot.cor_df <- function(rdf,
pd$size = abs(pd$r)
pd$label = fashion(pd$r)

if(.order == "default") {
pd$x <- factor(pd$x, levels = row_order)
pd$y <- factor(pd$y, levels = rev(row_order))
}

plot_ <- list(
# Geoms
geom_point(shape = shape),
Expand Down Expand Up @@ -230,8 +238,8 @@ network_plot.cor_df <- function(rdf,
scale_colour_gradientn(limits = c(-1, 1), colors = colours),
# Plot the points
geom_point(data = points,
aes(x, y),
size = 3, shape = 19, colour = "white"),
aes(x, y),
size = 3, shape = 19, colour = "white"),
# Plot variable labels
if (repel) ggrepel::geom_text_repel(data = points,
aes(x, y, label = id),
Expand All @@ -243,9 +251,9 @@ network_plot.cor_df <- function(rdf,
fontface = 'bold', size = 5),
# expand the axes to add space for curves
expand_limits(x = c(min(points$x) - .1,
max(points$x) + .1),
y = c(min(points$y) - .1,
max(points$y) + .1)
max(points$x) + .1),
y = c(min(points$y) - .1,
max(points$y) + .1)
),
# Theme and legends
theme_void(),
Expand Down
13 changes: 10 additions & 3 deletions R/output.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,15 @@ fashion.default <- function(x, decimals = 2, leading_zeros = FALSE, na_print = "
#'
#' @param rdf Correlation data frame (see \code{\link{correlate}}) or object
#' that can be coerced to one (see \code{\link{as_cordf}}).
#' @param legend Boolean indicating whether a legend mapping the colors to the correlations should be displayed.
#' @param legend Boolean indicating whether a legend mapping the colors to the
#' correlations should be displayed.
#' @param shape \code{\link{geom_point}} aesthetic.
#' @param print_cor Boolean indicating whether the correlations should be printed over the shapes.
#' @param print_cor Boolean indicating whether the correlations should be
#' printed over the shapes.
#' @param colours,colors Vector of colors to use for n-color gradient.
#' @param .order Either "default", meaning x and y variables keep the same order
#' as the columns in \code{x}, or "alphabet", meaning the variables are
#' alphabetized.
#' @return Plots a correlation data frame
#' @export
#' @examples
Expand All @@ -90,7 +95,9 @@ rplot <- function(rdf,
shape = 16,
colours = c("indianred2", "white", "skyblue1"),
print_cor = FALSE,
colors) {
colors,
.order = c("default", "alphabet")) {
.order <- match.arg(.order)
UseMethod("rplot")
}

Expand Down
6 changes: 3 additions & 3 deletions R/reshape.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#' function, see \code{\link[dplyr]{select}}.
#'
#' @param x cor_df. See \code{\link{correlate}}.
#' @param ... One or more unquoted expressions separated by commas. Variable
#' names can be used as if they were positions in the data frame, so
#' @param ... One or more unquoted expressions separated by commas. Variable
#' names can be used as if they were positions in the data frame, so
#' expressions like `x:y`` can be used to select a range of variables.
#' @param .dots Use focus_ to do standard evaluations. See \code{\link[dplyr]{select}}.
#' @param mirror Boolean. Whether to mirror the selected columns in the rows or
Expand All @@ -32,7 +32,7 @@ focus <- function(x, ..., mirror = FALSE) {
.dots = ...,
... = ...,
mirror = mirror
)
)
}

#' Returns a correlation table with the selected fields only
Expand Down
Binary file modified man/figures/README-combination-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions man/focus.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/network_plot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions man/rplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c6c6fe1

Please sign in to comment.