[R] cluster data in lattice dotplot and show stdev
Jim Lemon
drjimlemon at gmail.com
Thu Feb 16 22:53:40 CET 2017
Hi Luigi,
Are you looking for something like this?
library(plotrix)
ylim=c(0,1.7)
png("lmplot.png",width=600,height=300)
par(mfrow=c(1,2))
brkdn.plot(value~type,data=my.data[my.data$target=="A",],
main="Run 1",ylab="Value",xlab="",xaxlab="target",ylim=ylim,
mct="mean",md="sd",pch=c("B","N","P"))
brkdn.plot(value~type,data=my.data[my.data$target=="B",],
main="Run 2",ylab="Value",xlab="",xaxlab="target",ylim=ylim,
mct="mean",md="sd",pch=c("B","N","P"))
dev.off()
Jim
On Fri, Feb 17, 2017 at 2:30 AM, Luigi Marongiu
<marongiu.luigi at gmail.com> wrote:
> 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]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lmplot.png
Type: image/png
Size: 2787 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20170217/0e9cbc02/attachment.png>
More information about the R-help
mailing list