Skip to content

Instantly share code, notes, and snippets.

@kbroman
Last active August 29, 2015 14:11
Show Gist options
  • Save kbroman/58d43e7c4813d66c5ec2 to your computer and use it in GitHub Desktop.
Save kbroman/58d43e7c4813d66c5ec2 to your computer and use it in GitHub Desktop.
set.seed(91820205)
n <- 50
nlev <- 5
ncol <- 4
x <- rnorm(n)
y <- factor(sample(1:nlev, n, replace=TRUE), levels=1:nlev)
z <- factor(sample(1:ncol, n, replace=TRUE), levels=1:ncol)
library(broman)
color <- brocolors("crayons")[c("Outrageous Orange", "Jungle Green", "Plum", "Purple Pizzazz")]
stripchart(x ~ y, method="jitter", pch=21, bg=color[z])
set.seed(91820205)
n <- 50
nlev <- 5
ncol <- 4
x <- rnorm(n)
y <- factor(sample(1:nlev, n, replace=TRUE), levels=1:nlev)
z <- factor(sample(1:ncol, n, replace=TRUE), levels=1:ncol)
library(broman)
color <- brocolors("crayons")[c("Outrageous Orange", "Jungle Green", "Plum", "Purple Pizzazz")]
jit <- 0.1
r <- runif(n, -jit, jit)
yv <- as.numeric(y) + r
grayplot(x, yv, pch=21, bg=color[z], yat=1:nlev,
hlines.lwd=2, hlines.col="gray70",
v_over_h=TRUE, ylim=c(0.5, nlev+0.5))
@kbroman
Copy link
Author

kbroman commented Dec 17, 2014

a colleague asked how to color points in stripchart

@kbroman
Copy link
Author

kbroman commented Dec 18, 2014

Turns out, stripchart doesn't really use the colors properly. It takes the first few colors and just repeats them for all points, so they aren't really used properly.

@kbroman
Copy link
Author

kbroman commented Dec 18, 2014

I added an example of how I use the grayplot function in my R/broman package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment