First get v0.1.6 of yarrr from github
devtools::install_github("ndphillips/yarrr")
library(yarrr)
I’ll use the ChickWeight data and add 10 random points to highlight in the plot
data <- ChickWeight
# Select some random data points to highlight
data$highlight <- FALSE
data$highlight[sample(nrow(data), size = 10)] <- TRUE
Now I’ll create a pointpars dataframe indicating, for each row, some additional parameters for the points depending on whether they are highlighted or not.
# Create custom point parameters depending on whether data is highlighted or not
pointpars <- data.frame(col = ifelse(data$highlight, "red", "black"), # highlighted points in red
jitter = ifelse(data$highlight, .1, -.1), # put highlighted points on right
labels = ifelse(data$highlight, rownames(data)[data$highlight], ""), # add labels (just the row name) for highlighted points
pos = ifelse(data$highlight, 4, 2),#,
cex.labels = ifelse(data$highlight, .8, 0)
)
Here is the default plot (without pointpars)
pirateplot(weight ~ Diet,
theme = 2,
data = data)
Here it is with the point parameters
pirateplot(weight ~ Diet,
data = data,
theme = 2,
pointpars = pointpars)
Another version (different theme, exluding custom jitter)
pirateplot(weight ~ Diet,
theme = 2,
data = data,
pointpars = pointpars[, (names(pointpars) != "jitter")])