mirror of
https://github.com/agdamsbo/FreesearchR.git
synced 2026-06-19 04:27:30 +02:00
feat: new likert plot
This commit is contained in:
parent
ce0ecef633
commit
ba03109416
2 changed files with 64 additions and 2 deletions
50
R/plot_likert.R
Normal file
50
R/plot_likert.R
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
#' Nice horizontal bar plot centred on the central category
|
||||||
|
#'
|
||||||
|
#' @returns ggplot2 object
|
||||||
|
#' @export
|
||||||
|
#'
|
||||||
|
#' @name data-plots
|
||||||
|
#'
|
||||||
|
#' @examples
|
||||||
|
#' mtcars |> plot_likert(pri = "carb", sec = "cyl")
|
||||||
|
#' mtcars |> plot_likert(pri = "carb", sec = "cyl", ter="am")
|
||||||
|
#' mtcars |> plot_likert(pri = "cyl",color.palette="Blues")
|
||||||
|
#' mtcars |> plot_likert(pri = "carb", sec = NULL,color.palette="Magma")
|
||||||
|
#' mtcars |> plot_likert(pri = "carb", sec = c("cyl","am"),color.palette="Viridis")
|
||||||
|
plot_likert <- function(data,
|
||||||
|
pri,
|
||||||
|
sec = NULL,
|
||||||
|
ter = NULL,
|
||||||
|
color.palette = "viridis") {
|
||||||
|
if (!is.null(ter)) {
|
||||||
|
ds <- split(data, data[ter])
|
||||||
|
} else {
|
||||||
|
ds <- list(data)
|
||||||
|
}
|
||||||
|
out <- lapply(ds, \(.x) {
|
||||||
|
.x[c(pri, sec)] |>
|
||||||
|
# na.omit() |>
|
||||||
|
plot_likert_single(color.palette = color.palette)
|
||||||
|
})
|
||||||
|
|
||||||
|
wrap_plot_list(out, title = glue::glue(i18n$t("Grouped by {get_label(data,ter)}")))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
plot_likert_single <- function(data, color.palette = "viridis") {
|
||||||
|
ggstats::gglikert(data = data) +
|
||||||
|
scale_fill_generate(palette=color.palette)+
|
||||||
|
ggplot2::theme(
|
||||||
|
# legend.position = "none",
|
||||||
|
# panel.grid.major = element_blank(),
|
||||||
|
# panel.grid.minor = element_blank(),
|
||||||
|
# axis.text.y = ggplot2::element_blank(),
|
||||||
|
# axis.title.y = ggplot2::element_blank(),
|
||||||
|
text = ggplot2::element_text(size = 12)
|
||||||
|
# axis.text = ggplot2::element_blank(),
|
||||||
|
# plot.title = element_blank(),
|
||||||
|
# panel.background = ggplot2::element_rect(fill = "white"),
|
||||||
|
# plot.background = ggplot2::element_rect(fill = "white"),
|
||||||
|
# panel.border = ggplot2::element_blank()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
% Generated by roxygen2: do not edit by hand
|
% Generated by roxygen2: do not edit by hand
|
||||||
% Please edit documentation in R/data_plots.R, R/plot_bar.R, R/plot_box.R,
|
% Please edit documentation in R/data_plots.R, R/plot_bar.R, R/plot_box.R,
|
||||||
% R/plot_hbar.R, R/plot_ridge.R, R/plot_sankey.R, R/plot_scatter.R,
|
% R/plot_hbar.R, R/plot_likert.R, R/plot_ridge.R, R/plot_sankey.R,
|
||||||
% R/plot_violin.R
|
% R/plot_scatter.R, R/plot_violin.R
|
||||||
\name{data-plots}
|
\name{data-plots}
|
||||||
\alias{data-plots}
|
\alias{data-plots}
|
||||||
\alias{data_visuals_ui}
|
\alias{data_visuals_ui}
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
\alias{plot_box}
|
\alias{plot_box}
|
||||||
\alias{plot_box_single}
|
\alias{plot_box_single}
|
||||||
\alias{plot_hbars}
|
\alias{plot_hbars}
|
||||||
|
\alias{plot_likert}
|
||||||
\alias{plot_ridge}
|
\alias{plot_ridge}
|
||||||
\alias{sankey_ready}
|
\alias{sankey_ready}
|
||||||
\alias{plot_sankey}
|
\alias{plot_sankey}
|
||||||
|
|
@ -48,6 +49,8 @@ plot_box_single(data, pri, sec = NULL, seed = 2103, color.palette = "viridis")
|
||||||
|
|
||||||
plot_hbars(data, pri, sec, ter = NULL, color.palette = "viridis")
|
plot_hbars(data, pri, sec, ter = NULL, color.palette = "viridis")
|
||||||
|
|
||||||
|
plot_likert(data, pri, sec = NULL, ter = NULL, color.palette = "viridis")
|
||||||
|
|
||||||
plot_ridge(data, x, y, z = NULL, color.palette = "viridis", ...)
|
plot_ridge(data, x, y, z = NULL, color.palette = "viridis", ...)
|
||||||
|
|
||||||
sankey_ready(data, pri, sec, numbers = "count", ...)
|
sankey_ready(data, pri, sec, numbers = "count", ...)
|
||||||
|
|
@ -107,6 +110,8 @@ ggplot2 object
|
||||||
|
|
||||||
ggplot2 object
|
ggplot2 object
|
||||||
|
|
||||||
|
ggplot2 object
|
||||||
|
|
||||||
data.frame
|
data.frame
|
||||||
|
|
||||||
ggplot2 object
|
ggplot2 object
|
||||||
|
|
@ -128,6 +133,8 @@ Create nice box-plots
|
||||||
|
|
||||||
Nice horizontal stacked bars (Grotta bars)
|
Nice horizontal stacked bars (Grotta bars)
|
||||||
|
|
||||||
|
Nice horizontal bar plot centred on the central category
|
||||||
|
|
||||||
Plot nice ridge plot
|
Plot nice ridge plot
|
||||||
|
|
||||||
Readying data for sankey plot
|
Readying data for sankey plot
|
||||||
|
|
@ -164,6 +171,11 @@ mtcars |> plot_hbars(pri = "carb", sec = "cyl", ter="am")
|
||||||
mtcars |> plot_hbars(pri = "carb", sec = NULL,color.palette="Blues")
|
mtcars |> plot_hbars(pri = "carb", sec = NULL,color.palette="Blues")
|
||||||
mtcars |> plot_hbars(pri = "carb", sec = NULL,color.palette="Magma")
|
mtcars |> plot_hbars(pri = "carb", sec = NULL,color.palette="Magma")
|
||||||
mtcars |> plot_hbars(pri = "carb", sec = NULL,color.palette="Viridis")
|
mtcars |> plot_hbars(pri = "carb", sec = NULL,color.palette="Viridis")
|
||||||
|
mtcars |> plot_likert(pri = "carb", sec = "cyl")
|
||||||
|
mtcars |> plot_likert(pri = "carb", sec = "cyl", ter="am")
|
||||||
|
mtcars |> plot_likert(pri = "cyl",color.palette="Blues")
|
||||||
|
mtcars |> plot_likert(pri = "carb", sec = NULL,color.palette="Magma")
|
||||||
|
mtcars |> plot_likert(pri = "carb", sec = c("cyl","am"),color.palette="Viridis")
|
||||||
mtcars |>
|
mtcars |>
|
||||||
default_parsing() |>
|
default_parsing() |>
|
||||||
plot_ridge(x = "mpg", y = "cyl")
|
plot_ridge(x = "mpg", y = "cyl")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue