Plot weighted frequency matrix Plot weighted frequency matrix r r

Plot weighted frequency matrix


You can produce this plot...

enter image description here

... by using this code:

boring <- function(x, occ) occ/xboring_seq <- function(occ, length.out){  x <- seq(occ, length.out=length.out)  data.frame(x = x, y = boring(x, occ))}numbet <- 31odds <- 6plot(1, 0, type="n",      xlim=c(1, numbet + odds), ylim=c(0, 1),    yaxp=c(0,1,2),    main="Frequency matrix",     xlab="Successive occasions",    ylab="Relative frequency"    )axis(2, at=c(0, 0.5, 1))    for(i in 1:odds){  xy <- boring_seq(i, numbet+1)  lines(xy$x, xy$y, type="o", cex=0.5)}for(i in 1:numbet){  xy <- boring_seq(i, odds+1)  lines(xy$x, 1-xy$y, type="o", cex=0.5)}


You can also use Koshke's method, by limiting the combinations of values to those with s<6 and at Andrie's request added the condition on the difference of Ps$n and ps$s to get a "pointed" configuration.

 ps <- ldply(0:35, function(i)data.frame(s=0:i, n=i)) plot.new() plot.window(c(0,36), c(0,1)) apply(ps[ps$s<6 & ps$n - ps$s < 30, ], 1, function(x){   s<-x[1]; n<-x[2];   lines(c(n, n+1, n, n+1), c(s/n, s/(n+1), s/n, (s+1)/(n+1)), type="o")}) axis(1) axis(2) lines(6:36, 6/(6:36), type="o") # need to fill in the unconnected points on the upper frontier

Resulting plot (version 2)


Weighted Frequency Matrix is also called Position Weight Matrix (in bioinformatics).It can be represented in a form of a sequence logo.This is at least how I plot weighted frequency matrix.

library(cosmo)data(motifPWM); attributes(motifPWM) # Loads a sample position weight matrix (PWM) containing 8 positions.plot(motifPWM) # Plots the PWM as sequence logo.