FlowViz log ticks trick
1
0
Entering edit mode
drambald ▴ 80
@drambald-4243
Last seen 10.2 years ago
Hi, I was unable to find a emthod/parameter to draw tickmarks corriesponding to LOG decades for flow-cytometry data. I have then implemented my method (is brutal but seems effective). RESULT: http://img510.imageshack.us/i/pkhlinear.png/ CODE: # SET number of channels and log decades channels <- 65535 decades <- 4 plot(mData[[1]], "PE", breaks=256, col="orange", ylim=c(0,2500), main="PKH26", axes=F) axis(2) # calculate the main tickmarks my.fact <- channels / decades # main ticks axis(1, at=c(0,my.fact,my.fact*2,my.fact*3,my.fact*4), labels=c(expression(10^0), expression(10^1), expression(10^2), expression(10^3), expression(10^4))) # small ticks decade.one <- log(2:9) decade.one.log.ticks <- c(round((decade.one*my.fact)/max(decade.one))) axis(1, decade.one.log.ticks, labels=FALSE) decade.two.log.ticks <- decade.one.log.ticks + round(my.fact) axis(1, decade.two.log.ticks, labels=FALSE) decade.three.log.ticks <- decade.two.log.ticks + round(my.fact) axis(1, decade.three.log.ticks, labels=FALSE) decade.four.log.ticks <- decade.three.log.ticks + round(my.fact) axis(1, decade.four.log.ticks, labels=FALSE) It is this code correct? There is a better way to do this? Best Regards Davide Rambaldi
• 1.2k views
ADD COMMENT
0
Entering edit mode
Greg Finak ▴ 240
@greg-finak-4299
Last seen 7.8 years ago
United States
Hi, David. That is the correct mechanism for plotting custom axes. There are no explicit parameters for passing custom axes to the flowViz plotting functions. If you are working with flowFrames, you could still pass the axes=FALSE parameter to the plot method to get the same behaviour. The only thing you must be certain of is that the mapping from channel-space to log-intensity space is correct. Given that you are working with log base 10, you should be using log(X,base=10) in your code rather than log(), which is base 2. Also, I don't think you are constructing your minor ticks correctly (see below). You could construct your axes in one fell swoop, something along the lines of: #Artifical data points with 65535 channels X<-log(1:10000,10)*65535/4 plot(X,axes=FALSE) ### channels<-65535 decades=4 my.fact<-channels/decades. all.ticks<-NULL; major<-(10^(0:decades)) for(i in 1:(length(major)-1)){ all.ticks<-c(all.ticks,seq(major[i],major[i+1],l=10)) } all.ticks<-log(all.ticks,10); #Log base 10 major<-log(major,10); axis(2,all.ticks*my.fact,label=FALSE) axis(2,at=major*my.fact,labels=c(expression(10^0), expression(10^1), expression(10^2), expression(10^3), expression(10^4))) ##You could do the same using flowFrames require(flowCore) require(flowViz) X<-as.matrix(cbind(X,X)) colnames(X)<-c("A","B") X<-flowFrame(X); plot(X,axes=FALSE) #Calls the plot function in the flowViz package axis(2,all.ticks*my.fact,label=FALSE) axis(2,at=major*my.fact,labels=c(expression(10^0), expression(10^1), expression(10^2), expression(10^3), expression(10^4))) axis(1,all.ticks*my.fact,label=FALSE) axis(1,at=major*my.fact,labels=c(expression(10^0), expression(10^1), expression(10^2), expression(10^3), expression(10^4))) On 2011-02-23, at 7:42 AM, Davide Rambaldi wrote: > Hi, I was unable to find a emthod/parameter to draw tickmarks corriesponding to LOG decades for flow-cytometry data. > > I have then implemented my method (is brutal but seems effective). > > RESULT: http://img510.imageshack.us/i/pkhlinear.png/ > > CODE: > > # SET number of channels and log decades > channels <- 65535 > decades <- 4 > > plot(mData[[1]], "PE", breaks=256, col="orange", ylim=c(0,2500), main="PKH26", axes=F) > axis(2) > > # calculate the main tickmarks > my.fact <- channels / decades > > # main ticks > axis(1, at=c(0,my.fact,my.fact*2,my.fact*3,my.fact*4), labels=c(expression(10^0), expression(10^1), expression(10^2), expression(10^3), expression(10^4))) > > # small ticks > decade.one <- log(2:9) > decade.one.log.ticks <- c(round((decade.one*my.fact)/max(decade.one))) #You want 10 ticks from 1 to 10, 10 to 100, 100 to 1000, etc. s<-seq(1,10,length=10) minor.one <-log(s,10)*my.fact s<-seq(10,100,length=10) minor.two<-log(s,10)*my.fact etc... Cheers, Greg. > axis(1, decade.one.log.ticks, labels=FALSE) > decade.two.log.ticks <- decade.one.log.ticks + round(my.fact) > axis(1, decade.two.log.ticks, labels=FALSE) > decade.three.log.ticks <- decade.two.log.ticks + round(my.fact) > axis(1, decade.three.log.ticks, labels=FALSE) > decade.four.log.ticks <- decade.three.log.ticks + round(my.fact) > axis(1, decade.four.log.ticks, labels=FALSE) > > > It is this code correct? There is a better way to do this? > > Best Regards > > Davide Rambaldi > _______________________________________________ > Bioconductor mailing list > Bioconductor at r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor Greg Finak, PhD Post-doctoral Research Associate PS Statistics, Vaccine and Infectious Disease Division. Fred Hutchinson Cancer Research Center Seattle, WA (206)667-3116 gfinak at fhcrc.org
ADD COMMENT
0
Entering edit mode
Hi Greg, Thanks for your answer and for your corrections. I end up with a small function called "logticks": logticks <- function(channels = 1024, decades = 4) { my.fact<-channels/decades all.ticks<-NULL major<-(10^(0:decades)) for(i in 1:(length(major)-1)) { all.ticks<-c(all.ticks,seq(major[i],major[i+1],l=10)) } all.ticks<-unique(log(all.ticks,10)); #Log base 10 and remove duplicates major<-log(major,10) my.labels <- formatC(10^major, format="e", digits=0) # labels my.ticks <- list(major = (major*my.fact), all = (all.ticks*my.fact), labels = my.labels) return(my.ticks) } It returns a list with your ticks, the major ticks (scaled by your factor) and the labels for your major ticks. Default values: 1024 channels, 4 decades. Usage: my.ticks <- logticks(<channels>, <decades>) example: plot(mData[[1]], "PE", breaks=256, col="orange", main="PKH26", axes=F); # <-- CALL FlowViz axis(2) my.ticks <- logticks(65536,4) axis(1,my.ticks$all,label=FALSE) axis(1,at=my.ticks$major,labels=my.ticks$labels) Cheers Davide R. On Feb 23, 2011, at 6:55 PM, Greg Finak wrote: > Hi, David. > That is the correct mechanism for plotting custom axes. There are no explicit parameters for passing custom axes to the flowViz plotting functions. If you are working with flowFrames, you could still pass the axes=FALSE parameter to the plot method to get the same behaviour. The only thing you must be certain of is that the mapping from channel-space to log-intensity space is correct. Given that you are working with log base 10, you should be using log(X,base=10) in your code rather than log(), which is base 2. Also, I don't think you are constructing your minor ticks correctly (see below). You could construct your axes in one fell swoop, something along the lines of: > > #Artifical data points with 65535 channels > X<-log(1:10000,10)*65535/4 > plot(X,axes=FALSE) > ### > > channels<-65535 > decades=4 > my.fact<-channels/decades. > > all.ticks<-NULL; > major<-(10^(0:decades)) > for(i in 1:(length(major)-1)){ > all.ticks<-c(all.ticks,seq(major[i],major[i+1],l=10)) > } > all.ticks<-log(all.ticks,10); #Log base 10 > major<-log(major,10); > > axis(2,all.ticks*my.fact,label=FALSE) > axis(2,at=major*my.fact,labels=c(expression(10^0), expression(10^1), expression(10^2), expression(10^3), expression(10^4))) > > ##You could do the same using flowFrames > require(flowCore) > require(flowViz) > > X<-as.matrix(cbind(X,X)) > colnames(X)<-c("A","B") > X<-flowFrame(X); > plot(X,axes=FALSE) #Calls the plot function in the flowViz package > axis(2,all.ticks*my.fact,label=FALSE) > axis(2,at=major*my.fact,labels=c(expression(10^0), expression(10^1), expression(10^2), expression(10^3), expression(10^4))) > axis(1,all.ticks*my.fact,label=FALSE) > axis(1,at=major*my.fact,labels=c(expression(10^0), expression(10^1), expression(10^2), expression(10^3), expression(10^4))) > > > On 2011-02-23, at 7:42 AM, Davide Rambaldi wrote: > >> Hi, I was unable to find a emthod/parameter to draw tickmarks corriesponding to LOG decades for flow-cytometry data. >> >> I have then implemented my method (is brutal but seems effective). >> >> RESULT: http://img510.imageshack.us/i/pkhlinear.png/ >> >> CODE: >> >> # SET number of channels and log decades >> channels <- 65535 >> decades <- 4 >> >> plot(mData[[1]], "PE", breaks=256, col="orange", ylim=c(0,2500), main="PKH26", axes=F) >> axis(2) >> >> # calculate the main tickmarks >> my.fact <- channels / decades >> >> # main ticks >> axis(1, at=c(0,my.fact,my.fact*2,my.fact*3,my.fact*4), labels=c(expression(10^0), expression(10^1), expression(10^2), expression(10^3), expression(10^4))) >> >> # small ticks >> decade.one <- log(2:9) > >> decade.one.log.ticks <- c(round((decade.one*my.fact)/max(decade.one))) > #You want 10 ticks from 1 to 10, 10 to 100, 100 to 1000, etc. > s<-seq(1,10,length=10) > minor.one <-log(s,10)*my.fact > s<-seq(10,100,length=10) > minor.two<-log(s,10)*my.fact > > etc... > > Cheers, > > Greg. > >> axis(1, decade.one.log.ticks, labels=FALSE) >> decade.two.log.ticks <- decade.one.log.ticks + round(my.fact) >> axis(1, decade.two.log.ticks, labels=FALSE) >> decade.three.log.ticks <- decade.two.log.ticks + round(my.fact) >> axis(1, decade.three.log.ticks, labels=FALSE) >> decade.four.log.ticks <- decade.three.log.ticks + round(my.fact) >> axis(1, decade.four.log.ticks, labels=FALSE) >> >> >> It is this code correct? There is a better way to do this? >> >> Best Regards >> >> Davide Rambaldi >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor at r-project.org >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor > > Greg Finak, PhD > Post-doctoral Research Associate > PS Statistics, Vaccine and Infectious Disease Division. > Fred Hutchinson Cancer Research Center > Seattle, WA > (206)667-3116 > gfinak at fhcrc.org > > > > > Davide Rambaldi, Bioinformatics PostDoc. ----------------------------------------------------- IFOM-IEO Campus Via Adamello 16, Milano I-20139 Italy [t] +39 02574303870 [e] davide.rambaldi at ifom-ieo-campus.it
ADD REPLY

Login before adding your answer.

Traffic: 887 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6