3

If you remember there is a nice version of table conceived by Tufte that include small quartile plots running next to the corresponding data rows:

enter image description here

There is an implementation of such solution in R using package NMOF and function qTable, which basically creates the table shown above and outputs it as a LaTeX code:

require(NMOF)
x <- rnorm(100, mean = 0, sd = 2)
y <- rnorm(100, mean = 1, sd = 2)
z <- rnorm(100, mean = 1, sd = 0.5)
X <- cbind(x, y, z)
qTable(X,filename="res.tex")#this will save qTable in tex format in current dir

This method of visualization seem to be especially useful if you have a small amount of information to present, and you don't want to waste a space for the full graph. But I would like to hack qTable a bit. Instead of displaying quantile plots, I would prefer to display standard errors of the mean. I am not great in hacking such functions, and I used brute force to do it. I replaced the line from the qTable function which computes quantiles:

A <- apply(X, 2L, quantile, c(0.25, 0.5, 0.75))

with something very brutal, that computes standard errors:

require(psych)#got 'SE' function to compute columns standard deviation     
M = colMeans(X)#column means
SE = SD(X)/sqrt(nrow(X))#standard error
SELo = M-SE#lower bound
SEHi = M+SE#upper bound
A = t(data.frame(SELo,M,SEHi))#combines it together

I know, I know it's possibly unsustainable approach, but it actually works to some extend - it plots standard errors but keeps this gap in the plot:

enter image description here

and I would like this gap to disappear.

Here is a qTable function with modification discussed above.

Ben
  • 41,615
  • 18
  • 132
  • 227
Geek On Acid
  • 6,330
  • 4
  • 44
  • 64
  • interesting idea - I think what you need to tweak is the Latex code that does the drawing, that is where the start and end points of those lines are specified, not in the R code. – atiretoo Jul 09 '12 at 20:59
  • @atiretoo: Yes, that's probably the case, but I still didn't figure out how to hack the LaTeX part. – Geek On Acid Jul 10 '12 at 15:42
  • When you say you'd like the gap to disappear, do you mean that you want something that looks like the plot for 'neutral' in your first included figure? – Josh O'Brien Jul 11 '12 at 23:02
  • @JoshO'Brien: Yes, pretty much like this one. – Geek On Acid Jul 12 '12 at 00:29

1 Answers1

3

To remove the gaps, you can insert these two lines:

B[2, ] <- B[3, ]
B[4, ] <- B[3, ]

right before the for loop that starts with

for (cc in 1L:dim(X)[2L]) {...

Why does it work? Reading the graph from left to right, the five rows of B correspond to where

1) the left segments start
2) the left segments ends
3) the dots are
4) the right segments start
5) the right segments end

so by forcing B[2, ] and B[4, ] to B[3, ] you are effectively getting rid of the gaps.

flodel
  • 87,577
  • 21
  • 185
  • 223