Last active
August 29, 2015 14:11
-
-
Save kbroman/58d43e7c4813d66c5ec2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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]) |
This file contains hidden or 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
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)) |
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.
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
a colleague asked how to color points in stripchart