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

improve continuous color labels and custom size #13

Merged
merged 1 commit into from
Mar 10, 2021
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
41 changes: 30 additions & 11 deletions R/functions_chr_int.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ pretty_plot_chr_int = function(.data,
.color = NULL,
.shape = NULL,
.size = NULL,
opacity = 1) {
opacity = 1,
is_size_fixed) {
# Comply with CRAN NOTES
. = NULL

Expand All @@ -66,22 +67,22 @@ pretty_plot_chr_int = function(.data,
when(

# If not defined
pull(., !!.color) %>% unique %>% is.na() ~ (.) %>% mutate(.color = "grey25"),
pull(., !!.color) %>% unique %>% is.na() %>% all() ~ (.) %>% mutate(.color = "grey25"),

# If continuous
quo_is_symbol(.color) &&
(.) %>%
select(!!.color) %>%
sapply(class) %in% c("numeric", "integer", "double") ~ {
order_ = findInterval(pull(., !!.color), sort(pull(., !!.color)))
(.) %>% mutate(.color = grDevices::colorRampPalette(viridis(n = 5))(n())[order_])
(.) %>% mutate(color_hexadecimal = grDevices::colorRampPalette(viridis(n = 5))(n())[order_])
},

# If discrete
quo_is_symbol(.color) ~ {
how_many_colors = .data %>% distinct(!!.color) %>% nrow
(.) %>%
mutate(.color =
mutate(color_hexadecimal =
grDevices::colorRampPalette(RColorBrewer::brewer.pal(min(
9, how_many_colors
), "Set1"))(how_many_colors)[factor(!!.color)])
Expand All @@ -91,10 +92,10 @@ pretty_plot_chr_int = function(.data,
# Define SIZE
when(
# If not defined
pull(., !!.size) %>% unique %>% is.na() ~ (.) %>% mutate(.size = 2),
pull(., !!.size) %>% unique %>% is.na() %>% all() ~ (.) %>% mutate(.size = 2),

# If it is a number and not a column name
class(.size) == "numeric" ~ (.) %>% mutate(.size := !!.size),
is_size_fixed ~ (.) %>% mutate(.size := !!.size),

# If continuous
quo_is_symbol(enquo(.size)) &&
Expand All @@ -117,7 +118,7 @@ pretty_plot_chr_int = function(.data,
when(

# If not defined
pull(., !!.shape) %>% unique %>% is.na() ~ (.) %>% mutate(.shape = 19),
pull(., !!.shape) %>% unique %>% is.na() %>% all() ~ (.) %>% mutate(.shape = 19),

# If continuous
quo_is_symbol(.shape) &
Expand Down Expand Up @@ -145,7 +146,7 @@ pretty_plot_chr_int = function(.data,
bty = 'l',
pch = (.) %>% pull(.shape),
cex = (.) %>% pull(.size),
col = (.) %>% pull(.color) %>% alpha(opacity),
col = (.) %>% pull(color_hexadecimal) %>% alpha(opacity),
xlab = quo_names(.dim1) %>% paste(collapse = " "),
ylab = quo_names(.dim2) %>% paste(collapse = " "),
xaxt = 'n',
Expand Down Expand Up @@ -188,9 +189,21 @@ pretty_plot_chr_int = function(.data,
legend(
"topleft",
inset = c(1.05, inset_y),
legend = distinct(.data,!!.color) %>% pull(!!.color),
legend = .data_formatted %>%

# If continuous
when(
pull(., !!.color) %>% class %in% c("numeric", "integer", "double") ~ arrange(., !!.color) %>% slice(1, n()) %>% pull(!!.color) %>% round(digits = 4),
~ arrange(., !!.color) %>% distinct(!!.color) %>% pull(!!.color)
),
pch = 19,
col = distinct(.data_formatted,!!.color, .color) %>% pull(.color),
col = .data_formatted %>%

# If continuous
when(
pull(., !!.color) %>% class %in% c("numeric", "integer", "double") ~ arrange(., !!.color) %>% slice(1, n()) %>% pull(color_hexadecimal),
~ arrange(., !!.color) %>% distinct(color_hexadecimal) %>% pull(color_hexadecimal)
),
title = color_title,
box.col = "white",
xjust = 0
Expand Down Expand Up @@ -265,6 +278,7 @@ gate_interactive_chr_int <-
.size = NULL,
opacity = 1,
how_many_gates = 1,
is_size_fixed,
...) {
# Comply with CRAN NOTES
. = NULL
Expand Down Expand Up @@ -321,7 +335,8 @@ gate_interactive_chr_int <-
# size can be number or column
.size = !!.size,

opacity = opacity
opacity = opacity,
is_size_fixed = is_size_fixed
)

# Loop over gates # Variable needed for recalling the attributes later
Expand Down Expand Up @@ -475,6 +490,10 @@ gate_programmatic_chr_int <-

opacity = opacity,
how_many_gates = how_many_gates,
is_size_fixed =
class(.size) %in% c("numeric", "integer", "double") &
length(.size) < length(.dim1) &
length(.size) == 1,
...
),

Expand Down
1 change: 1 addition & 0 deletions man/gate_interactive_chr_int.Rd

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