-
Notifications
You must be signed in to change notification settings - Fork 88
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
Group-wise color in scatterplot #113
Comments
Thanks for using DataExplorer. For your need, you will have to tweak the source code a little. Copy & paste the following function and you should be able to pass plot_scatterplot2 <- function(data, by, group, sampled_rows = nrow(data), geom_point_args = list(), title = NULL, ggtheme = theme_gray(), theme_config = list(), nrow = 3L, ncol = 3L, parallel = FALSE) {
variable <- NULL
if (!is.data.table(data)) data <- data.table(data)
if (sampled_rows < nrow(data)) data <- data[sample.int(nrow(data), sampled_rows)]
dt <- suppressWarnings(melt.data.table(data, id.vars = c(by, group), variable.factor = FALSE))
feature_names <- unique(dt[["variable"]])
layout <- DataExplorer:::.getPageLayout(nrow, ncol, length(feature_names))
plot_list <- DataExplorer:::.lapply(
parallel = parallel,
X = layout,
FUN = function(x) {
ggplot(dt[variable %in% feature_names[x]], aes_string(x = by, y = "value", color = group)) +
do.call("geom_point", geom_point_args) +
coord_flip() +
xlab(by)
}
)
class(plot_list) <- c("multiple", class(plot_list))
plotDataExplorer(
plot_obj = plot_list,
page_layout = layout,
title = title,
ggtheme = ggtheme,
theme_config = theme_config,
facet_wrap_args = list(
"facet" = ~ variable,
"nrow" = nrow,
"ncol" = ncol,
"scales" = "free_x",
"shrink" = FALSE
)
)
} Then just do: plot_scatterplot2(tmp, by = "ess_score", group = "group") I tested it on plot_scatterplot2(iris, by = "Sepal.Length", group = "Species") |
Please also keep this issue open. I might be able to add this in future versions, but I can't promise which one. |
Thanks @boxuancui. I'll give it a shot. |
In general, having the ability to color (or assign other ggplot2 aesthetics) based on some groups defined in some column would be quite useful for many of the plotting functions (plot_density, etc.) |
Hello,
First, thank you for your awesome product. I really appreciate the data exploration tool you've put together.
I'm trying to figure out if certain functionality exists. I'm running DataExplorer v 0.8.0.
I have the following dataframe:
I'd like to produce ess x rpcsq scatterplots (5 scatterplots) with the points colored by group. I've tried the following:
This works but obviously doesn't color the points. The following code however fails to produce the plots:
Does the functionality I'm looking for exist in the current iteration of DataExplorer? Thanks for any help you can be.
The text was updated successfully, but these errors were encountered: