Skip to content

Commit 9246851

Browse files
committed
Updated plots slightly
1 parent 2afc9f6 commit 9246851

19 files changed

Lines changed: 445 additions & 76 deletions

R/binomial.R

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,7 @@ binomnorm <- function(k, n, prob, direction) {
222222
#'
223223
#' @examples
224224
binompower <- function(LOS, n, prob1, alternative, prob2 = NULL) {
225-
Description <- "iscambinompower(LOS, n, prob1, alternative, prob2) \n This function determines the rejection region \n corresponding to the level of significance and the first probability \n and shows the second distribution shading its corresponding region. \n alternative can be \"less\", \"greater\", or \"two.sided\"."
226-
227-
if (as.character(LOS) == "?") {
228-
stop(Description)
229-
}
230-
231-
thisx <- 0:max(n)
225+
thisx <- 0:n
232226
minx <- max(
233227
0,
234228
min(

R/overlayDensities.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#' Template documentation for plotting parameters
22
#'
33
#' @param x A numeric vector representing the data to be plotted.
4-
#' @param main What to title the graph.
5-
#' @param xlab What to label the x-axis.
6-
#' @param bins Number of bins for the histogram.
4+
#' @param main Optional title for the plot
5+
#' @param xlab Optional x-axis label for the plot
6+
#' @param bins Optional number of bins for the histogram.
77
#'
88
#' @keywords internal
99
#' @name .add_density_common_params
@@ -190,7 +190,6 @@ addtnorm <- function(
190190
)
191191
}
192192

193-
194193
#' Common processing for plotting histogram and overlaying arbitrary densities
195194
#'
196195
#' This internal helper function handles the core logic of creating a histogram

R/plots.R

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,71 @@
1+
#' Template documentation for plotting parameters
2+
#'
3+
#' @param response Vector of numeric values to plot.
4+
#' @param explanatory Optional second categorical variable to group by.
5+
#' @param main Optional title for the plot
6+
#' @param xlab Optional x-axis label for the plot
7+
#' @param ylab Optional y-axis label for the plot. Only displayed when `explanatory` is provided.
8+
#'
9+
#' @keywords internal
10+
#' @name .plot_funcs_common_params
11+
NULL
12+
113
#' A box plot
214
#'
315
#' `boxplot` plots the given data in a box plot. If a second categorical variable
416
#' is given, the data is grouped by this variable.
517
#'
6-
#' @param x Vector of numeric values to plot.
7-
#' @param explanatory Optional second categorical variable to group by.
8-
#' @param main Optional title for the plot
9-
#' @param xlab Optional x-axis label for the plot
10-
#' @param ylab Optional y-axis for the plot
18+
#' @inheritParams .plot_funcs_common_params
1119
#'
1220
#' @return A box plot.
1321
#'
1422
#' @export
1523
#'
16-
#'
1724
#' @examples
25+
#' boxplot(
26+
#' mtcars$mpg,
27+
#' main = "mtcars Cylinders Dotplot",
28+
#' xlab = "Number of Cylinders"
29+
#' )
30+
#' boxplot(
31+
#' mtcars$mpg,
32+
#' mtcars$am,
33+
#' main = "Automatic Cars Have Better Mileage on Average",
34+
#' xlab = "Mileage (miles per gallon)",
35+
#' ylab = "Automatic (yes coded as 1)"
36+
#' )
1837
boxplot <- function(
19-
x,
38+
response,
2039
explanatory = NULL,
2140
main = "",
2241
xlab = "",
2342
ylab = substitute(explanatory)
2443
) {
25-
# TODO Masks graphics's boxplot?
26-
Description <- "iscamboxplot (x, explanatory, names) \n This function displays horizontal boxplot(s) utilizing quartiles instead of hinges to match the summary statistics. \n Optional: A second, categorical variable can also be specified \n and values will be calculated separately for each group. \n Use the names input to specify the horizontal and vertical axis labels respectively."
27-
28-
if (as.character(x[1]) == "?") {
29-
stop(Description)
30-
}
3144
withr::local_par(mar = c(4, 4, 2, 2))
3245

3346
if (is.null(explanatory)) {
3447
withr::local_par(mar = c(4, 3, 2, 2))
35-
qq <- quantile(x, na.rm = TRUE)
36-
bp <- graphics::boxplot(x, plot = FALSE)
48+
qq <- quantile(response, na.rm = TRUE)
49+
bp <- graphics::boxplot(response, plot = FALSE)
3750
bp$stats[2, 1] <- qq[2L]
3851
bp$stats[4, 1] <- qq[4L]
3952
bxp(bp, horizontal = TRUE, boxfill = "lightgrey")
4053
} else {
4154
mylabels <- names(table(explanatory))
4255
grouparray <- matrix(nrow = length(mylabels), ncol = 5)
43-
middle <- tapply(x, explanatory, quantile)
56+
middle <- tapply(response, explanatory, quantile)
4457
proportions <- table(explanatory) / length(explanatory)
45-
bp <- graphics::boxplot(x ~ explanatory, plot = FALSE)
58+
bp <- graphics::boxplot(response ~ explanatory, plot = FALSE)
4659
for (i in 1:length(mylabels)) {
4760
names(middle)[i] <- "group1"
4861
grouparray[i, ] <- (middle[i]$group1)
4962
bp$stats[2, i] <- grouparray[i, 2]
5063
bp$stats[4, i] <- grouparray[i, 4]
5164
}
52-
5365
bxp(bp, horizontal = TRUE, boxfill = "lightgrey", width = proportions)
54-
mtext(side = 2, line = 2, ylab)
5566
}
56-
mtext(side = 1, line = 2, xlab)
57-
invisible()
67+
title(main = main, xlab = xlab, ylab = ylab)
68+
invisible(response)
5869
}
5970

6071
#' A dot plot
@@ -63,30 +74,32 @@ boxplot <- function(
6374
#' given, the data is grouped by this variable. Use `names` & `mytitle` to
6475
#' specify the labels and title.
6576
#'
66-
#' @param response Vector of numeric values to plot.
67-
#' @param explanatory Optional second categorical variable to group by.
68-
#' @param main Optional title for the plot
69-
#' @param xlab Optional x-axis label for the plot
70-
#' @param ylab Optional y-axis for the plot
77+
#' @inheritParams .plot_funcs_common_params
7178
#'
7279
#' @return A dot plot.
7380
#'
7481
#' @export
7582
#'
7683
#' @examples
77-
#' dotplot(mtcars$cyl, main = "mtcars Cylinders Dotplot", xlab = "Cylinders", ylab = "Counts")
84+
#' dotplot(
85+
#' mtcars$cyl,
86+
#' main = "mtcars Cylinders Dotplot",
87+
#' xlab = "Number of Cylinders"
88+
#' )
89+
#' dotplot(
90+
#' mtcars$mpg,
91+
#' mtcars$am,
92+
#' main = "Automatic Cars Have Better Mileage on Average",
93+
#' xlab = "Mileage (miles per gallon)",
94+
#' ylab = "Automatic (yes coded as 1)"
95+
#' )
7896
dotplot <- function(
7997
response,
8098
explanatory = NULL,
8199
main = "",
82100
xlab = substitute(response),
83101
ylab = substitute(explanatory)
84102
) {
85-
Description <- "iscamdotplot(response, explanatory, names, mytitle) \n This function creates horizontal dotplots. \n If no explanatory variable is specified, just one plot. \n If an explanatory variable is specified, parallel dotplots will be created. \n Use the names input to specify the horizontal and vertical axis labels respectively and mytitle to specify main. Vertical axis cuts off at 1000."
86-
87-
if (as.character(response[1]) == "?") {
88-
stop(Description)
89-
}
90103
withr::local_par(mar = c(5, 1, 5, 1))
91104

92105
if (is.null(explanatory)) {
@@ -95,9 +108,7 @@ dotplot <- function(
95108
method = "stack",
96109
ylim = c(0, 1000),
97110
pch = 16,
98-
main = main,
99-
xlab = xlab,
100-
ylab = ylab
111+
xlab = ""
101112
)
102113
abline(h = 0)
103114
} else {
@@ -111,13 +122,12 @@ dotplot <- function(
111122
method = "stack",
112123
ylim = c(ymin, ymax),
113124
pch = 16,
114-
main = main,
115-
xlab = xlab,
116-
ylab = ylab
125+
xlab = ""
117126
)
118127
for (i in 1:numCategories) {
119128
abline(h = i)
120129
}
121130
}
131+
title(main = main, xlab = xlab, ylab = ylab)
122132
invisible()
123133
}

man/FlintMDEQ.Rd

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/addexp.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/addlnorm.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/addnorm.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/addt.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/addtnorm.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/boxplot.Rd

Lines changed: 17 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)