-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from nhejazi/develop
Develop
- Loading branch information
Showing
28 changed files
with
394 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
March 21, 2016: | ||
* The first (working) release of package `nima` is submitted to CRAN. | ||
September 20, 2016: | ||
* Addition of several functions, re-written DESCRIPTION file. Update of package | ||
version to v. 0.4.0. This version update to be released on CRAN. | ||
|
||
July 5, 2016: | ||
* Major changes, including addition of unit tests and Travis-CI coverage, added | ||
to the package for v. 0.3.5. This version update not to be released on CRAN. | ||
|
||
March 25, 2016: | ||
* The first public release of this package (v. 0.3.0) is made available on CRAN. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#' Add missingness indicators to existing data.frame | ||
#' | ||
#' Add indicator columns to a data.frame showing the pattern of missingness. | ||
#' | ||
#' @param data A numeric vector or array. | ||
#' @param prefix A string used to name the indicator variables.. | ||
#' | ||
#' @return An augmented data.frame with indicators for missingness patterns. | ||
#' | ||
#' @export | ||
#' | ||
#' @examples | ||
#' data <- data.frame(cbind(rnorm(10), runif(10))) | ||
#' data[sample(nrow(data), 3), 1] <- NA | ||
#' data[sample(nrow(data), 4), 2] <- NA | ||
#' data <- miss_ind(data) | ||
|
||
miss_ind <- function(data, prefix = "miss_") { | ||
indicators = sapply(data, FUN = function(col) as.numeric(is.na(col))) | ||
colnames(indicators) = paste0(prefix, colnames(data)) | ||
indicators = indicators[, !colMeans(indicators) %in% c(0, 1)] | ||
out <- cbind(data, indicators) | ||
return(out) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,100 @@ | ||
#' Nima's ggplot2 theme | ||
#' | ||
#' Nima's ggplot2 theme: black border and no ticks | ||
#' Nima's ggplot2 theme: white background, colors optimized | ||
#' | ||
#' @param base_size Base font size | ||
#' @param base_family Base font family | ||
#' @param ... Passed to \code{\link[ggplot2]{theme}} | ||
#' | ||
#' @importFrom ggplot2 ggplot | ||
#' @importFrom ggplot2 ggplot rel element_text element_rect element_line | ||
#' @importFrom ggplot2 element_blank | ||
#' @importFrom grid unit | ||
#' @importFrom ggthemes theme_foundation | ||
#' | ||
#' @export | ||
#' | ||
#' @return An object as returned by \code{\link[ggplot2]{theme}} | ||
#' | ||
#' @examples | ||
#' library(ggplot2) | ||
#' mtcars$cyl <- factor(mtcars$cyl) | ||
#' p <- ggplot(mtcars, aes(y=mpg, x = disp, color = cyl)) | ||
#' p <- p + geom_point() + theme_nima() | ||
#' p <- ggplot(mtcars, aes(y = mpg, x = disp, color = factor(cyl))) | ||
#' p <- p + geom_point() + scale_fill_nima() + scale_color_nima() + theme_nima() | ||
#' p | ||
#' | ||
#' @seealso | ||
#' \code{\link[ggplot2]{theme}} | ||
|
||
|
||
theme_nima <- function(base_size = 12, base_family = "", ...) { | ||
ggplot2::"%+replace%"( | ||
ggplot2::theme_grey(base_size = base_size, base_family = base_family), | ||
ggplot2::theme(axis.ticks.length = grid::unit(0, "cm"), | ||
panel.border = ggplot2::element_rect(fill = NA, | ||
color = "black"), | ||
strip.background=ggplot2::element_rect(fill="gray80", | ||
color="black"), ...) | ||
) | ||
theme_nima <- function(base_size = 14, base_family = "Helvetica") { | ||
(theme_foundation(base_size = base_size, base_family = base_family) | ||
+ theme(plot.title = element_text(face = "bold", | ||
size = rel(1.2), hjust = 0.5), | ||
text = element_text(), | ||
panel.background = element_rect(colour = NA), | ||
plot.background = element_rect(colour = NA), | ||
panel.border = element_rect(colour = NA), | ||
axis.title = element_text(face = "bold", size = rel(1)), | ||
axis.title.y = element_text(angle = 90, vjust = 2), | ||
axis.title.x = element_text(vjust = -0.2), | ||
axis.text = element_text(), | ||
axis.line = element_line(colour = "black"), | ||
axis.ticks = element_line(), | ||
axis.ticks.length = unit(0, "cm"), | ||
panel.grid.major = element_line(colour = "#f0f0f0"), | ||
panel.grid.minor = element_blank(), | ||
legend.key = element_rect(colour = NA), | ||
legend.position = "bottom", | ||
legend.direction = "horizontal", | ||
legend.key.size= unit(0.2, "cm"), | ||
legend.margin = unit(0, "cm"), | ||
legend.title = element_text(face = "italic"), | ||
plot.margin = unit(c(10, 5, 5, 5), "mm"), | ||
strip.background = element_rect(colour = "#f0f0f0", | ||
fill = "#f0f0f0"), | ||
strip.text = element_text(face = "bold") | ||
)) | ||
} | ||
|
||
#' @rdname theme_nima | ||
#' @export | ||
nima_theme <- theme_nima | ||
|
||
|
||
#' Nima's ggplot2 theme - supplement: scale_fill | ||
#' | ||
#' Nima's ggplot2 theme scale_fill supplement: colors optimized via ColorBrewer | ||
#' | ||
#' @param ... Passed to \code{\link[ggplot2]{ggplot}} | ||
#' | ||
#' @importFrom ggplot2 discrete_scale | ||
#' @importFrom scales manual_pal | ||
#' | ||
#' @export | ||
#' | ||
|
||
scale_fill_nima <- function(...){ | ||
discrete_scale("fill","nima", | ||
manual_pal(values = c("#386cb0","#fdb462","#7fc97f", | ||
"#ef3b2c","#662506","#a6cee3", | ||
"#fb9a99","#984ea3","#ffff33")), ...) | ||
} | ||
|
||
|
||
#' Nima's ggplot2 theme - supplement: scale_color | ||
#' | ||
#' Nima's ggplot2 theme scale_color supplement: colors optimized via ColorBrewer | ||
#' | ||
#' @param ... Passed to \code{\link[ggplot2]{ggplot}} | ||
#' | ||
#' @importFrom ggplot2 discrete_scale | ||
#' @importFrom scales manual_pal | ||
#' | ||
#' @export | ||
#' | ||
|
||
scale_color_nima <- function(...){ | ||
discrete_scale("colour","nima", | ||
manual_pal(values = c("#386cb0","#fdb462","#7fc97f", | ||
"#ef3b2c","#662506","#a6cee3", | ||
"#fb9a99","#984ea3","#ffff33")), ...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.onAttach <- function(...) { | ||
packageStartupMessage("nima: Nima Hejazi's Miscellaneous R Tools") | ||
packageStartupMessage("Version: ", utils::packageDescription("nima")$Version) | ||
} |
Oops, something went wrong.