Skip to content

Commit

Permalink
add new parameter for plot_scatter
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxu98 committed Jun 8, 2024
1 parent e28cdff commit bfaf813
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
27 changes: 19 additions & 8 deletions R/plotting_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
#' @param compute_correlation_method Method to compute correlation ("pearson" or "spearman").
#' @param keep_aspect_ratio Logical value, whether to set aspect ratio to 1:1.
#' @param facet Faceting variable. If setting TRUE, all settings about margins will be inalidation.
#' @param se Display confidence interval around smooth
#' @param se Display confidence interval around smooth.
#' @param pointdensity Plot point density when only provide 1 cluster.
#'
#' @return ggplot object
#' @export
Expand All @@ -33,12 +34,16 @@
#' )
#' )
#'
#' plot_scatter(test_data, keep_aspect_ratio = TRUE)
#' plot_scatter(test_data, facet = TRUE, keep_aspect_ratio = TRUE)
#' plot_scatter(test_data, marginal_type = "density", keep_aspect_ratio = TRUE)
#' plot_scatter(test_data, marginal_type = "boxplot", keep_aspect_ratio = TRUE)
#' plot_scatter(test_data[, 1:2], keep_aspect_ratio = TRUE)
#' plot_scatter(test_data[, 1:2], marginal_type = "histogram", keep_aspect_ratio = TRUE)
#' p1 <- plot_scatter(test_data, keep_aspect_ratio = TRUE)
#'
#' p2 <- plot_scatter(test_data, marginal_type = "boxplot", keep_aspect_ratio = TRUE)
#' p1 + p2
#' p3 <- plot_scatter(test_data, facet = TRUE, keep_aspect_ratio = TRUE)
#' p3
#'
#' p4 <- plot_scatter(test_data[, 1:2], marginal_type = "histogram", keep_aspect_ratio = TRUE)
#' p5 <- plot_scatter(test_data[, 1:2], keep_aspect_ratio = TRUE)
#' p4 + p6
plot_scatter <- function(
data,
smoothing_method = "lm",
Expand All @@ -56,7 +61,8 @@ plot_scatter <- function(
compute_correlation_method = "pearson",
keep_aspect_ratio = FALSE,
facet = FALSE,
se = FALSE) {
se = FALSE,
pointdensity = TRUE) {
smoothing_method <- match.arg(smoothing_method, c("lm", "loess"))
compute_correlation_method <- match.arg(
compute_correlation_method, c("pearson", "spearman")
Expand Down Expand Up @@ -84,6 +90,11 @@ plot_scatter <- function(
formula = "y ~ x",
se = se
)
if (pointdensity) {
p <- p +
ggpointdensity::geom_pointdensity() +
viridis::scale_color_viridis()
}
marginal_group_colour <- FALSE
marginal_group_fill <- FALSE
} else {
Expand Down
23 changes: 15 additions & 8 deletions man/plot_scatter.Rd

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

0 comments on commit bfaf813

Please sign in to comment.