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

size.by & opacity.by parameters for jitter/scatter plots #7

Open
j-andrews7 opened this issue Jan 15, 2024 · 2 comments
Open

size.by & opacity.by parameters for jitter/scatter plots #7

j-andrews7 opened this issue Jan 15, 2024 · 2 comments

Comments

@j-andrews7
Copy link
Contributor

To encode yet another piece of data in the plot.

@j-andrews7
Copy link
Contributor Author

j-andrews7 commented Jul 6, 2024

This can already be done with size, but it's only mentioned in the details rather than the parameter itself. And doesn't work with do.letter. Using do.hover with it also results in a single combined legend for color.by and size, which is functionally uninterpretable.

set.seed(1)
library(palmerpenguins)
df <- as.data.frame(penguins[!apply(penguins, 1, function(x) { any(is.na(x)) }), ])

rownames(df) <- paste0("row", rownames(df))

# Dimensionality reduction
pca <- prcomp(df[, c("bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g")])
df <- cbind(df, pca$x)

# Additional 'random' observations
df$groups <- sample(c("A","B","C","D","E"), nrow(df), replace = TRUE)
df$age <- sample(c("1","2","3","4"), nrow(df), replace = TRUE)
df$number <- as.numeric(seq_len(nrow(df)))

scatterPlot(
        df, x.by = "PC1", y.by = "PC2",
        color.by = "island",
        size = "number", do.hover = TRUE)

image

Versus this with do.hover = FALSE:

image

The do.letter error just requires a few checks in .add_letters to overcome, but the do.hover issue is inherent to plotly (see plotly/plotly.R#2163) and unlikely to be fixed until the underlying plotly.js version used by the R package is updated (and this bug is fixed plotly/plotly.js#7023).

@j-andrews7
Copy link
Contributor Author

Added this same functionality to opacity in #19, and cleaned up the docs a bit to make it more clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant