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

Merge into main #160

Merged
merged 1 commit into from
May 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- `correlate()` now removes non-numeric columns from data frame inputs (@thisisdaryn, #139).
- `autoplot.cor_df()` method have been added fot quick generation of correlation chart.
- `network_plot()` now allows the user the option to map the color range to the range of correlations that are in the input `rdf` (@thisisdaryn, #158).

# corrr 0.4.3

Expand Down
17 changes: 13 additions & 4 deletions R/cor_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,13 @@ rplot.cor_df <- function(rdf,
#' @export
network_plot.cor_df <- function(rdf,
min_cor = .30,
legend = TRUE,
legend = c("full", "range", "none"),
colours = c("indianred2", "white", "skyblue1"),
repel = TRUE,
curved = TRUE,
colors) {
legend <- rlang::arg_match(legend)

if (min_cor < 0 || min_cor > 1) {
rlang::abort("min_cor must be a value ranging from zero to one.")
}
Expand Down Expand Up @@ -260,6 +262,13 @@ network_plot.cor_df <- function(rdf,
}
}

if(legend %in% c("full", "none")){
legend_range = c(-1, 1)
}
else if(legend == "range"){
legend_range = c(min(rdf[row(rdf)!=col(rdf)]),
max(rdf[row(rdf)!=col(rdf)]))
}
plot_ <- list(
# For plotting paths
if (curved) {
Expand All @@ -284,7 +293,7 @@ network_plot.cor_df <- function(rdf,
},
scale_alpha(limits = c(0, 1)),
scale_size(limits = c(0, 1)),
scale_colour_gradientn(limits = c(-1, 1), colors = colours),
scale_colour_gradientn(limits = legend_range, colors = colours),
# Plot the points
geom_point(
data = points,
Expand Down Expand Up @@ -322,8 +331,8 @@ network_plot.cor_df <- function(rdf,
# Theme and legends
theme_void(),
guides(size = "none", alpha = "none"),
if (legend) labs(colour = NULL),
if (!legend) theme(legend.position = "none")
if (legend != "none") labs(colour = NULL),
if (legend == "none") theme(legend.position = "none")
)

ggplot() + plot_
Expand Down
6 changes: 5 additions & 1 deletion R/output.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ rplot.default <- function(rdf, ...) {
#'
#' @param min_cor Number from 0 to 1 indicating the minimum value of
#' correlations (in absolute terms) to plot.
#' @param legend How should the colors and legend for the correlation values be
#' displayed? The options are "full" (the default) for -1 to 1 with a legend,
#' "range" for the range of correlation values in \code{rdf} with a legend,
#' or "none" for colors between -1 to 1 with no legend displayed.
#' @param colours,colors Vector of colors to use for n-color gradient.
#' @param repel Should variable labels repel each other? If TRUE, text is added
#' via \code{\link[ggrepel]{geom_text_repel}} instead of \code{\link[ggplot2]{geom_text}}
Expand All @@ -141,7 +145,7 @@ rplot.default <- function(rdf, ...) {
#' network_plot(x, min_cor = .7, colors = c("red", "green"), legend = TRUE)
network_plot <- function(rdf,
min_cor = .3,
legend = TRUE,
legend = c("full", "range", "none"),
colours = c("indianred2", "white", "skyblue1"),
repel = TRUE,
curved = TRUE,
Expand Down
3 changes: 1 addition & 2 deletions man/colpair_map.Rd

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

1 change: 0 additions & 1 deletion man/dice.Rd

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

8 changes: 4 additions & 4 deletions man/focus.Rd

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

8 changes: 5 additions & 3 deletions man/network_plot.Rd

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

4 changes: 2 additions & 2 deletions man/rearrange.Rd

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

4 changes: 2 additions & 2 deletions man/shave.Rd

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

10 changes: 5 additions & 5 deletions man/stretch.Rd

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