Skip to content

Commit

Permalink
Use ggally_count in ggduo and ggpairs discrete plots (#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
schloerke committed May 30, 2020
1 parent e9ec315 commit 11e3846
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export(ggally_blankDiag)
export(ggally_box)
export(ggally_box_no_facet)
export(ggally_cor)
export(ggally_cor_v1_5)
export(ggally_count)
export(ggally_countDiag)
export(ggally_cor_v1_5)
export(ggally_density)
export(ggally_densityDiag)
export(ggally_denstrip)
Expand Down Expand Up @@ -94,8 +94,8 @@ export(range01)
export(rescale01)
export(rescale11)
export(scatmat)
export(stat_ggally_count)
export(signif_stars)
export(stat_ggally_count)
export(uppertriangle)
export(v1_ggmatrix_theme)
export(wrap)
Expand Down
9 changes: 5 additions & 4 deletions R/gg-plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -1394,9 +1394,10 @@ ggally_count <- function(data, mapping, ...) {
if (is.null(mapping$y)) stop("'y' aesthetic is required.")
# for stat_ggally_count(), y should be mapped to base_y
# and always be a factor
data$.y <- as.factor(eval_data_col(data, mapping$y))
count_col <- ".ggally_y"
data[[count_col]] <- as.factor(eval_data_col(data, mapping$y))
ylabel <- mapping_string(mapping$y)
mapping$base_y <- aes_string(base_y = ".y")$base_y
mapping$base_y <- aes_string(base_y = count_col)$base_y
mapping$y <- NULL

# default values
Expand All @@ -1407,8 +1408,8 @@ ggally_count <- function(data, mapping, ...) {
ggplot(data, mapping) +
do.call(stat_ggally_count, args) +
scale_y_continuous(
breaks = 1:length(levels(data$.y)),
labels = levels(data$.y)
breaks = 1:length(levels(data[[count_col]])),
labels = levels(data[[count_col]])
) +
theme(panel.grid.minor = element_blank()) +
ylab(ylabel)
Expand Down
9 changes: 5 additions & 4 deletions R/ggpairs.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

# discrete
# ratio
# count
# facetbar
# blank

Expand Down Expand Up @@ -451,7 +452,7 @@ ggduo <- function(
continuous = "smooth_loess",
comboVertical = "box_no_facet",
comboHorizontal = "facethist",
discrete = "ratio"
discrete = "count"
),
axisLabels = c("show", "none"),
columnLabelsX = colnames(data[columnsX]),
Expand Down Expand Up @@ -498,7 +499,7 @@ ggduo <- function(

types <- check_and_set_ggpairs_defaults(
"types", types,
continuous = "smooth_loess", discrete = "ratio", na = "na",
continuous = "smooth_loess", discrete = "count", na = "na",
isDuo = TRUE
)

Expand Down Expand Up @@ -777,7 +778,7 @@ ggpairs <- function(
mapping = NULL,
columns = 1:ncol(data),
title = NULL,
upper = list(continuous = "cor", combo = "box_no_facet", discrete = "facetbar", na = "na"),
upper = list(continuous = "cor", combo = "box_no_facet", discrete = "count", na = "na"),
lower = list(continuous = "points", combo = "facethist", discrete = "facetbar", na = "na"),
diag = list(continuous = "densityDiag", discrete = "barDiag", na = "naDiag"),
params = NULL,
Expand Down Expand Up @@ -820,7 +821,7 @@ ggpairs <- function(

upper <- check_and_set_ggpairs_defaults(
"upper", upper,
continuous = "cor", combo = "box_no_facet", discrete = "facetbar", na = "na"
continuous = "cor", combo = "box_no_facet", discrete = "count", na = "na"
)
lower <- check_and_set_ggpairs_defaults(
"lower", lower,
Expand Down
2 changes: 1 addition & 1 deletion man/ggduo.Rd

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

2 changes: 1 addition & 1 deletion man/ggpairs.Rd

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

0 comments on commit 11e3846

Please sign in to comment.