Skip to content

Commit

Permalink
Merge pull request #11 from ibecav/newv
Browse files Browse the repository at this point in the history
Release v0.5.7
  • Loading branch information
ibecav committed Jun 12, 2019
2 parents 765a736 + 138be03 commit 770a265
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 12 deletions.
6 changes: 3 additions & 3 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.4
Version: 0.5.7
Authors@R: person("Chuck", "Powell", email = "ibecav@gmail.com", role = c("aut", "cre"))
Description: Miscellaneous functions useful for teaching statistics as well as actually practicing the art. They typically are not “new” methods but rather wrappers around either base R or other packages.
Depends: R (>= 3.5.0)
Expand All @@ -13,11 +13,11 @@ Imports:
DescTools,
devtools,
dplyr,
ggplot2 (>= 2.2.1),
ggplot2,
ggrepel,
methods,
pwr,
rlang (>= 0.1.6),
rlang,
scales,
sjstats,
tibble
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ importFrom(dplyr,mutate)
importFrom(dplyr,n)
importFrom(dplyr,select)
importFrom(dplyr,summarise)
importFrom(ggrepel,geom_label_repel)
importFrom(ggrepel,geom_text_repel)
importFrom(grDevices,nclass.FD)
importFrom(methods,is)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# CGPfunctions 0.5.4

* Release 0.5.7 feature release 12 June 2019
- Updated newslopegraph to add aditional formatting options
* Release 0.5.4 hotfix release 8 April 2019
- Updated Plot2WayANOVA to remedy an error when there were zero significant effects
and post hoc tests failed
Expand Down
50 changes: 44 additions & 6 deletions R/newggslopegraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,22 @@
#' SubTitleTextSize = 10 is the default must be a numeric.
#' @param CaptionTextSize Optionally the font size for the Caption to be displayed.
#' CaptionTextSize = 8 is the default must be a numeric.
#' @param LineThickness Optionally the thickness of the plotted lines. LineThickness = 1
#' is the default must be a numeric.
#' @param LineThickness Optionally the thickness of the plotted lines that
#' connect the data points. LineThickness = 1 is the default must be a numeric.
#' @param DataTextSize Optionally the font size of the plotted data points. DataTextSize = 2.5
#' is the default must be a numeric.
#' @param DataTextColor Optionally the font color of the plotted data points. `"black"`
#' is the default can be either `colors()` or hex value e.g. "#FF00FF".
#' @param DataLabelPadding Optionally the amount of space between the plotted
#' data point numbers and the label "box". By default very small = 0.05 to
#' avoid overlap. Must be a numeric. Too large a value will risk "hiding"
#' datapoints.
#' @param DataLabelLineSize Optionally how wide a line to plot around the data
#' label box. By default = 0 to have no visible border line around the
#' label. Must be a numeric.
#' @param DataLabelFillColor Optionally the fill color or background of the
#' plotted data points. `"white"` is the default can be any of the `colors()`
#' or hex value e.g. "#FF00FF".
#' @param LineColor Optionally the color of the plotted lines. By default it will use
#' the ggplot2 color palette for coloring by \code{Grouping}. The user may override
#' with \bold{one} valid color of their choice e.g. "black" (see colors() for choices)
Expand All @@ -64,7 +76,7 @@
#' @export
#' @import ggplot2
#' @importFrom dplyr filter mutate group_by summarise %>% n
#' @importFrom ggrepel geom_text_repel
#' @importFrom ggrepel geom_text_repel geom_label_repel
#'
#' @author Chuck Powell
#' @seealso \code{\link{newcancer}} and \code{\link{newgdp}}
Expand Down Expand Up @@ -95,7 +107,19 @@
#' LineColor = c("black", "red", "grey"),
#' LineThickness = .5,
#' WiderLabels = TRUE)
#'
#'
#' # not a great example but demonstrating functionality
#' newgdp$rGDP <- round(newgdp$GDP)
#'
#' newggslopegraph(newgdp,
#' Year,
#' rGDP,
#' Country,
#' LineColor = c(rep("grey", 3), "red", rep("grey", 11)),
#' DataTextSize = 3,
#' DataLabelFillColor = "gray",
#' DataLabelPadding = .2,
#' DataLabelLineSize = .5)
#'
newggslopegraph <- function(dataframe, Times, Measurement, Grouping,
Title = "No title given",
Expand All @@ -109,6 +133,10 @@ newggslopegraph <- function(dataframe, Times, Measurement, Grouping,
LineThickness = 1,
LineColor = "ByGroup",
DataTextSize = 2.5,
DataTextColor = "black",
DataLabelPadding = 0.05,
DataLabelLineSize = 0,
DataLabelFillColor = "white",
WiderLabels = FALSE,
RemoveMissing = TRUE)
{
Expand Down Expand Up @@ -217,6 +245,7 @@ newggslopegraph <- function(dataframe, Times, Measurement, Grouping,
dataframe %>%
ggplot(aes_(group=Grouping, y=Measurement, x=Times)) +
LineGeom +
# left side y axis labels
geom_text_repel(data = . %>% filter(!! Times == min(!! Times)),
aes_(label = Grouping) ,
hjust = "left",
Expand All @@ -227,6 +256,7 @@ newggslopegraph <- function(dataframe, Times, Measurement, Grouping,
size = YTextSize,
nudge_x = -1.95,
direction = "y") +
# right side y axis labels
geom_text_repel(data = . %>% filter(!! Times == max(!! Times)),
aes_(label = Grouping),
hjust = "right",
Expand All @@ -237,10 +267,18 @@ newggslopegraph <- function(dataframe, Times, Measurement, Grouping,
size = YTextSize,
nudge_x = 1.95,
direction = "y") +
# data point labels
geom_label(aes_(label = Measurement),
size = DataTextSize,
label.padding = unit(0.05, "lines"),
label.size = 0.0) +
# label.padding controls fill padding
label.padding = unit(DataLabelPadding, "lines"),
# label.size controls width of line around label box
# 0 = no box line
label.size = DataLabelLineSize,
# color = text color of label
color = DataTextColor,
# fill background color for data label
fill = DataLabelFillColor) +
MySpecial +
labs(
title = Title,
Expand Down
36 changes: 33 additions & 3 deletions man/newggslopegraph.Rd

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

0 comments on commit 770a265

Please sign in to comment.