Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Apr 13, 2024
1 parent f7341ae commit 0547187
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 6 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Added the following function(s): factorial_anova_2_way,
mixed_anova_2_way, ci_of_mean
* Updated the following function(s) (and other functions that use them):
two_way_anova, se_of_mean
two_way_anova, se_of_mean, theme_kim, plot_group_means

# kim 0.5.423
* Updated the following function(s) (and other functions that use them):
Expand Down
2 changes: 1 addition & 1 deletion R/factorial_anova_2_way.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ factorial_anova_2_way <- function(
error_bar_tip_width = 0.13,
error_bar_thickness = 1,
error_bar_caption = TRUE,
line_colors = NULL,
line_colors = c("red", "blue"),
line_types = NULL,
line_thickness = 1,
dot_size = 3,
Expand Down
69 changes: 66 additions & 3 deletions R/mixed_anova_2_way.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@
#' @param iv_name_bw_group_values restrict all analyses to
#' observations having these values for the between-group
#' independent variable
#' @param colors colors of the dots and lines connecting means
#' (default = NULL) If there are exactly two repeated measures,
#' then, by default, \code{line_colors = c("red", "blue")}
#' @param position_dodge by how much should the group means and error bars
#' be horizontally offset from each other so as not to overlap?
#' (default = 0.13)
#' @param legend_title a character for the legend title. If no input
#' is entered, then, by default, the legend title will be removed.
#' @param x_axis_expansion_add inputs for the \code{add} parameter
#' of the \code{expand} argument. The first and second values respectively
#' determine the amount of space to add to the left and right along
#' the x-axis. By default, \code{x_axis_expansion_add = c(0.2, 0.03)} which
#' means that space with the width of 0.2 will be added to the left, and
#' space with the width of 0.03 will be added to the right.
#' @param x_axis_title a character string for the x-axis title.
#' If \code{x_axis_title == FALSE}, which is the default value,
#' the x-axis title will be removed.
#' @param y_axis_title a character string for the y-axis title
#' (default = "Mean"). If \code{x_axis_title == FALSE}, the y-axis title
#' will be removed.
#' @param output output type can be one of the following:
#' \code{"plot"}, \code{"all"}
#' @examples
#' \donttest{
#' mixed_anova_2_way(
Expand All @@ -28,6 +50,12 @@ mixed_anova_2_way <- function(
iv_name_bw_group = NULL,
repeated_measures_col_names = NULL,
iv_name_bw_group_values = NULL,
colors = NULL,
position_dodge = 0.13,
legend_title = NULL,
x_axis_expansion_add = c(0.2, 0.03),
x_axis_title = NULL,
y_axis_title = "Mean",
output = "all") {
# installed packages
installed_pkgs <- rownames(utils::installed.packages())
Expand Down Expand Up @@ -109,6 +137,14 @@ mixed_anova_2_way <- function(
linetype = repeated_measure))
g1 <- g1 + ggplot2::geom_point(size = 5)
g1 <- g1 + ggplot2::geom_line(linewidth = 1)
# apply colors
if (num_of_dvs == 2) {
colors <- c("red", "blue")
}
if (!is.null(colors)) {
g1 <- g1 + ggplot2::scale_color_manual(
values = colors)
}
g1 <- g1 + ggplot2::geom_errorbar(
mapping = ggplot2::aes(
x = iv,
Expand All @@ -117,13 +153,40 @@ mixed_anova_2_way <- function(
ymax = ci_95_ul),
width = 0,
linewidth = 1)
# The errorbars will overlap,
# so use position_dodge to move them horizontally
pd <- ggplot2::position_dodge(width = position_dodge)
g1 <- g1 + kim::theme_kim(
legend_position = "right",
cap_axis_lines = TRUE)
g1 <- g1 + ggplot2::scale_x_discrete(
expand = ggplot2::expansion(add = c(0.2, 0.03)))
g1 <- g1 + ggplot2::theme(
axis.title.x = ggplot2::element_blank())
expand = ggplot2::expansion(add = x_axis_expansion_add))
# legend
if (is.null(legend_title)) {
g1 <- g1 + ggplot2::theme(
legend.title = ggplot2::element_blank())
} else {
g1 <- g1 + ggplot2::labs(
color = legend_title,
group = legend_title,
linetype = legend_title)
}
# axis titles
if (is.null(x_axis_title) || x_axis_title == FALSE) {
g1 <- g1 + ggplot2::theme(
axis.title.x = ggplot2::element_blank())
} else {
g1 <- g1 + ggplot2::labs(
x = x_axis_title)
}
if (is.null(y_axis_title) || y_axis_title == FALSE) {
g1 <- g1 + ggplot2::theme(
axis.title.y = ggplot2::element_blank())
} else {
g1 <- g1 + ggplot2::labs(
x = y_axis_title)
}
# print the plot
print(g1)
if (output == "plot") {
invisible(g1)
Expand Down
3 changes: 3 additions & 0 deletions R/theme_kim.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#' (default = 3)
#' @param base_size base font size
#' @param axis_tick_font_size font size for axis tick marks
#' @param axis_tick_marks_color color of the axis tick marks
#' @param axis_title_font_size font size for axis title
#' @param y_axis_title_vjust position of the y axis title (default = 0.85).
#' If default is used, \code{y_axis_title_vjust = 0.85}, the y axis title
Expand All @@ -40,6 +41,7 @@ theme_kim <- function(
legend_key_size = 3,
base_size = 20,
axis_tick_font_size = 20,
axis_tick_marks_color = "black",
axis_title_font_size = 24,
y_axis_title_vjust = 0.85,
axis_title_margin_size = 24,
Expand Down Expand Up @@ -88,6 +90,7 @@ theme_kim <- function(
face = "bold", color = "black", size = axis_title_font_size),
axis.text = ggplot2::element_text(
face = "bold", color= "black", size = axis_tick_font_size),
axis.ticks = ggplot2::element_line(colour = "black"),
legend.title = ggplot2::element_text(
face = "bold", color = "black", size = axis_title_font_size),
legend.text = ggplot2::element_text(
Expand Down
2 changes: 1 addition & 1 deletion man/factorial_anova_2_way.Rd

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

35 changes: 35 additions & 0 deletions man/mixed_anova_2_way.Rd

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

3 changes: 3 additions & 0 deletions man/theme_kim.Rd

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

0 comments on commit 0547187

Please sign in to comment.