Skip to content
Browse files

Merge branch 'master' into stata

  • Loading branch information...
2 parents 09f4b8a + 0e5f0c3 commit 283a393a70237771e4464460c2eb1837f5d6e223 @jrnold committed
Showing with 31 additions and 9 deletions.
  1. +3 −1 R/ggplotJrnoldPalettes.R
  2. +17 −5 R/utils.R
  3. +6 −2 man/show_linetypes.Rd
  4. +5 −1 man/show_shapes.Rd
View
4 R/ggplotJrnoldPalettes.R
@@ -61,7 +61,9 @@ ggplotJrnoldPalettes <- {
## bg : d5e4eb
## bgdk : c3d6df
x$economist$bg <-
- c(ebg = "#d5e4eb", edkbg = "#c3d6df")
+ c(ebg = "#d5e4eb", # Bluish gray
+ edkbg = "#c3d6df", # Darker bluish-gray
+ red = "#ed111a", # Bright red rectangle and highlights)
## From png 20120818_AMC820.png
## blue_gray = 6794a7
## blue_dark = 014d64
View
22 R/utils.R
@@ -27,12 +27,15 @@ cpaste <- function(..., sep=", ", collapse=NULL, and=TRUE) {
##' @export
##' @param shapes A numeric or character vector of shapes. See
##' \code{\link{par}}.
+##' @param labels Include the plotting character value of the symbol.
##' @seealso \code{\link[scales]{show_col}}, \code{\link{show_linetypes}}
##'
##' @examples
##' library(scales)
##' show_shapes(shape_pal()(5))
-show_shapes <- function(shapes) {
+##' show_shapes(shape_pal()(3), labels=TRUE)
+##'
+show_shapes <- function(shapes, labels=TRUE) {
n <- length(shapes)
ncol <- ceiling(sqrt(n))
nrow <- ceiling(n/ncol)
@@ -43,8 +46,10 @@ show_shapes <- function(shapes) {
type="n", xlab="", ylab="", axes=FALSE)
for (i in seq_len(ncol(shapes))) {
for (j in seq_len(nrow(shapes))) {
- print(c(i, j))
points(i, j, pch=shapes[j, i])
+ if (labels) {
+ text(i, j, shapes[j, i], pos=1, col="gray70")
+ }
}
}
}
@@ -56,18 +61,25 @@ show_shapes <- function(shapes) {
##' @export
##' @param linetypes A character vector of linetypes. See
##' \code{\link{par}}.
+##' @param labels Label each line with its linetype (lty) value.
+##'
##' @seealso \code{\link[scales]{show_col}}, \code{\link{show_linetypes}}
##'
##' @examples
##' library(scales)
-##' show_shapes(linetype_pal()(3))
-show_linetypes <- function(linetypes) {
+##' show_linetypes(linetype_pal()(3))
+##' show_linetypes(linetype_pal()(3), labels=TRUE)
+show_linetypes <- function(linetypes, labels=TRUE) {
n <- length(linetypes)
plot(0, 0, xlim=c(0, 1), ylim=c(n, 1),
type="n", xlab="", ylab="", axes=FALSE)
for (i in seq_along(linetypes)) {
abline(h=i, lty=linetypes[i])
}
- axis(side=2, at=seq_len(n), tick=FALSE, labels=seq_len(n), las=2)
+ if (labels) {
+ axis(side=2, at=seq_len(n), tick=FALSE, labels=linetypes, las=2)
+ } else {
+ axis(side=2, at=seq_len(n), tick=FALSE, labels=seq_len(n), las=2)
+ }
}
View
8 man/show_linetypes.Rd
@@ -2,18 +2,22 @@
\alias{show_linetypes}
\title{Show linetypes}
\usage{
- show_linetypes(linetypes)
+ show_linetypes(linetypes, labels = TRUE)
}
\arguments{
\item{linetypes}{A character vector of linetypes. See
\code{\link{par}}.}
+
+ \item{labels}{Label each line with its linetype (lty)
+ value.}
}
\description{
A quick and dirty way to show linetypes.
}
\examples{
library(scales)
-show_shapes(linetype_pal()(3))
+show_linetypes(linetype_pal()(3))
+show_linetypes(linetype_pal()(3), labels=TRUE)
}
\seealso{
\code{\link[scales]{show_col}},
View
6 man/show_shapes.Rd
@@ -2,11 +2,14 @@
\alias{show_shapes}
\title{Show shapes}
\usage{
- show_shapes(shapes)
+ show_shapes(shapes, labels = TRUE)
}
\arguments{
\item{shapes}{A numeric or character vector of shapes.
See \code{\link{par}}.}
+
+ \item{labels}{Include the plotting character value of the
+ symbol.}
}
\description{
A quick and dirty way to show shapes.
@@ -14,6 +17,7 @@
\examples{
library(scales)
show_shapes(shape_pal()(5))
+show_shapes(shape_pal()(3), labels=TRUE)
}
\seealso{
\code{\link[scales]{show_col}},

0 comments on commit 283a393

Please sign in to comment.
Something went wrong with that request. Please try again.