Re: [R] cluster data in lattice dotplot and show stdev
Hi Luigi I think your data is duplicated > xtabs(~cluster+type+target,my.data) , , target = A type cluster blank negative positive run_1 222 run_2 000 , , target = B type cluster blank negative positive run_1 000 run_2 222 > xtabs(~cluster+target,my.data) target cluster A B run_1 6 0 run_2 0 6 I am not sure exactly what you want partly because what Jim has plotted. I have thought of 2 ways. I have added columns coding the factors as numeric to make it flexible 1. By runs my.data$Target <- paste0(rep(LETTERS[1:2],each= 6),rep(1:2,each=3)) my.data$x <- rep(c(0.8,1.2),each=3) my.data$xrun <- rep(1:3) xyplot(value ~ x|target,my.data, groups = type, xlim = c(0.5,1.5), scales = list(x = list(at= c(0.8,1.2), label=paste("Run",1:2)), alternating = 1), auto.key = list(points = T, lines = F), pch=16, panel = panel.superpose, panel.groups = function(x,y,...){ panel.xyplot(x,y, ...) } ) 2. By type xyplot(value ~ xrun|target,my.data, groups = run, xlim = c(0,4), par.settings = list(strip.background = list(col = "transparent")), scales = list(x = list(at= c(1:3), label= unique(my.data$type), alternating = 1)), auto.key = list(points = T, lines = F), pch=16, panel = panel.superpose, panel.groups = function(x,y,...){ panel.xyplot(x,y, ...) } ) If you want error bars use the functions in demo(lattice::intervals) or use your own panel .segments If you decide not to use default colours etc use panel.settings = list(superpose.symbol = list(pch = ... , col = ... , cex = 1)) makes keys easier example by hand error bars xyplot(value ~ xrun|target,my.data, groups = run, xlim = c(0,4), par.settings = list(strip.background = list(col = "transparent"), grid.pars = list(lineend = "butt")), scales = list(x = list(at= c(1:3), label= unique(my.data$type), alternating = 1)), auto.key = list(points = T, lines = F), pch=16, panel = panel.superpose, panel.groups = function(x,y,...,group.number){ panel.xyplot(x,y, ...) panel.arrows(group.number+0.3, group.number-0.6, group.number+0.3, group.number-0.4, length = 0.04, unit = "inches", angle = 90, code = 3) } ) Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luigi Marongiu Sent: Friday, 17 February 2017 02:31 To: r-help Subject: [R] cluster data in lattice dotplot and show stdev 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.se
Re: [R] cluster data in lattice dotplot and show stdev
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 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@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. __ R-help@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.
[R] cluster data in lattice dotplot and show stdev
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@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.