[R] cluster data in lattice dotplot and show stdev
Luigi Marongiu
marongiu.luigi at gmail.com
Thu Feb 16 16:30:57 CET 2017
dear all,
i have a set of data that is separated in the variables: cluster (two
runs), type (blank, negative and positive) and target (A and B), each
duplicated. I am plotting it with lattice and the result is a 2x2 matrix
plot in which the top two cells (or panels) are relative to run 2, the
lower to run 2; each panel is then subdivided in target A or B and I have
colour-coded the dots to match the target.
However i would like to have a 1x2 panel plot representing the targets, and
within each panel having a cluster of 3 dots (representing the types) for
run 1 and another for run 2. I tried to represent such requirement in the
rough construction at the end of the example.
also, since each run is actually formed by duplicates, each dot should
indicate the standard deviation of the values.
How would I do that? any tips?
thanks
luigi
>>>
cluster <- c(rep("run_1", 6), rep("run_2", 6))
type <- rep(c("blank", "positive", "negative"),2)
target <- c(rep("A", 6), rep("B", 6))
value <- c(0.01, 1.1, 0.5,
0.02, 1.6, 0.8,
0.07, 1.4, 0.7,
0.03, 1.4, 0.4)
my.data <- data.frame(cluster, type, target, value)
library(lattice)
dotplot(
value ~ type|cluster + target,
my.data,
groups = type,
pch=21,
main = "Luminex analysis MTb humans",
xlab = "Target", ylab = "Reading",
col = c("grey", "green", "red"),
par.settings = list(strip.background = list(col="paleturquoise")),
scales = list(alternating = FALSE, x = list(labels = c("", "", ""))),
key = list(
space = "top",
columns = 3,
text = list(c("Blank", "Negative", "Positive"), col="black"),
rectangles = list(col=c("grey", "green", "red"))
)
)
x <- 1:7
plot(x , c(max(my.data$value), min(my.data$value), my.data$value[1:5]),
col="white", xaxt = "n", ylab="value", xlab="target")
points(x[1], mean(my.data$value[1], my.data$value[4]), col="grey")
points(x[2], mean(my.data$value[2], my.data$value[5]), col="red")
points(x[3], mean(my.data$value[3], my.data$value[6]), col="green")
points(x[5], mean(my.data$value[7], my.data$value[10]), col="grey")
points(x[6], mean(my.data$value[8], my.data$value[11]), col="red")
points(x[7], mean(my.data$value[9], my.data$value[12]), col="green")
axis(side=1, at = x[2], lab = "A", cex.axis=1)
axis(side=1, at = x[6], lab = "B", cex.axis=1)
[[alternative HTML version deleted]]
More information about the R-help
mailing list