Skip to content

Commit

Permalink
Merge pull request #19 from ibecav/v6.0.0
Browse files Browse the repository at this point in the history
V6.0.0
  • Loading branch information
ibecav committed Mar 25, 2020
2 parents 1c319c2 + 6e4b0bc commit 9a044c7
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 35 deletions.
11 changes: 6 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: CGPfunctions
Title: Powell Miscellaneous Functions for Teaching and Learning Statistics
Version: 0.5.9
Version: 0.6.0
Authors@R: person("Chuck",
"Powell",
email = "ibecav@gmail.com",
Expand All @@ -16,19 +16,20 @@ Imports:
BayesFactor,
broom,
car,
DescTools,
DescTools (>= 0.99.32),
dplyr,
forcats,
ggplot2,
ggmosaic (>= 0.2.0),
ggplot2 (>= 3.3.0),
ggrepel,
grid,
methods,
paletteer,
partykit,
purrr,
rlang,
scales,
sjstats,
scales (>= 1.1.0),
sjstats (>= 0.17.9),
stats,
stringr,
tidyr
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ importFrom(dplyr,select)
importFrom(dplyr,summarise)
importFrom(dplyr,summarize)
importFrom(forcats,fct_rev)
importFrom(ggmosaic,geom_mosaic)
importFrom(ggmosaic,product)
importFrom(ggrepel,geom_label_repel)
importFrom(ggrepel,geom_text_repel)
importFrom(grDevices,nclass.FD)
Expand Down
9 changes: 7 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# CGPfunctions 0.5.9
# CGPfunctions 0.6.0

* Release 0.5.9 in development March 2020
* Release 0.6.0 in development March 2020
- Fixed dependency issues with ggplot2, scales, sjstats and added ggmosaic
- Adding mosaic plots to PlotXTabs2 still debugging and waiting on the next version
of ggmosaic for some bu fixes

* Release 0.5.9 deployed to CRAN March 2020
- Added functionality to PlotXTabs2 will be deprecating PlotXtabs next
release
- Another vignette example for newggslopegraph
Expand Down
103 changes: 87 additions & 16 deletions R/PlotXTabs2.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
#' @importFrom BayesFactor extractBF
#' @importFrom BayesFactor contingencyTableBF
#' @importFrom sjstats crosstable_statistics
#' @importFrom ggmosaic geom_mosaic product
#' @importFrom scales label_percent
#'
#' @author Chuck Powell, Indrajeet Patil
#'
Expand Down Expand Up @@ -323,6 +325,8 @@ PlotXTabs2 <- function(data,
} else if (!missing(labels.legend)) {
legend.labels <- labels.legend
}

# return(df)

### ----- start main plot ============================

Expand Down Expand Up @@ -372,6 +376,46 @@ PlotXTabs2 <- function(data,
alpha = label.fill.alpha,
na.rm = TRUE
)
} else if (plottype == "mosaic") {
p <- ggplot2::ggplot(data = df) +
geom_mosaic(aes(weight = counts, x = product(x), fill = y)) +
scale_y_continuous(labels = scales::label_percent(accuracy = 1.0),
breaks = seq(from = 0,
to = 1,
by = 0.10),
minor_breaks = seq(from = 0.05,
to = 0.95,
by = 0.10))

### ---- Extract mosaic info and calculate cell pcts
mosaicgeominfo <-
ggplot_build(p)$data[[1]] %>%
group_by_at(vars(ends_with("__x"))) %>%
mutate(NN = sum(.wt)) %>%
mutate(pct = (.wt/NN))

p <- p + geom_label(data = mosaicgeominfo,
aes(x = (xmin + xmax)/2,
y = (ymin + ymax)/2,
label = scales::percent(pct,
accuracy = .1)
),
size = label.text.size,
fill = label.fill.color,
alpha = label.fill.alpha
)



# ) +
# ggplot2::geom_label(
# mapping = ggplot2::aes(label = data.label,
# group = y),
# show.legend = FALSE,
# position = position_stack(vjust = 0.5),
# size = label.text.size,
# na.rm = TRUE
# )
} else {
p <- ggplot2::ggplot(
data = df,
Expand Down Expand Up @@ -494,7 +538,7 @@ PlotXTabs2 <- function(data,

### ----- adding sample size info on x axis -------

if (plottype == "percent") {
if (plottype == "percent" || plottype == "mosaic") {
y_adjustment <- -0.05
} else {
y_adjustment <- -0.05 * max(df$counts)
Expand All @@ -503,22 +547,49 @@ PlotXTabs2 <- function(data,
}
}

if (isTRUE(sample.size.label)) {
p <-
p +
ggplot2::geom_text(
data = df_n_label,
mapping = ggplot2::aes(
x = x,
y = y_adjustment,
label = N,
fill = NULL
),
size = 4,
na.rm = TRUE
)
}
if (plottype != "mosaic") {
if (isTRUE(sample.size.label)) {
p <-
p +
ggplot2::geom_text(
data = df_n_label,
mapping = ggplot2::aes(
x = x,
y = y_adjustment,
label = N,
fill = NULL
),
size = 4,
na.rm = TRUE
)
}
} else {
if (isTRUE(sample.size.label)) {

### ---- Compute mosaic x axis label tick positions
xNlabelpos <-
mosaicgeominfo %>%
distinct(xNlabelpos = ((xmax - xmin)/2) + xmin) %>%
pull(xNlabelpos)

# return(xNlabelpos)

p <-
p +
ggplot2::geom_text(
data = df_n_label,
mapping = ggplot2::aes(
x = xNlabelpos,
y = y_adjustment,
label = N,
fill = NULL
),
size = 4,
na.rm = TRUE
)
}
}

### ----- if we need to modify `x`-axis orientation ----
if (!base::missing(x.axis.orientation)) {
if (x.axis.orientation == "slant") {
Expand Down
7 changes: 7 additions & 0 deletions R/global_vars.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
utils::globalVariables(
names = c(
".",
".wt",
"perc",
"N",
"NN",
"n",
"TheMean",
"TheSEM",
Expand All @@ -31,6 +33,11 @@ utils::globalVariables(
"logged",
"sensible",
"astext",
"xmin",
"xmax",
"ymin",
"ymax",
"pct",
"."
),
package = "CGPfunctions",
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

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

2 changes: 1 addition & 1 deletion docs/LICENSE-text.html

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

2 changes: 1 addition & 1 deletion docs/articles/index.html

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

2 changes: 1 addition & 1 deletion docs/authors.html

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

2 changes: 1 addition & 1 deletion docs/index.html

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

17 changes: 12 additions & 5 deletions docs/news/index.html

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

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pandoc: 2.9.2
pandoc: 2.9.2.1
pkgdown: 1.4.1
pkgdown_sha: ~
articles:
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/index.html

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

0 comments on commit 9a044c7

Please sign in to comment.