1

I have seen that you can change the colour of alternating rows and columns by using h.odd.alpha etc. I am wondering if there is a way to change the colour of only specific rows?

I have been asked to make reports including tables of the data (please dont reference sweave or knitr because I know about these packages already) however they want the tables presented horizontally however as there are many data points this means that the table exceeds the dimensions of an A4 page. I have found a way to split my table so that it shows with half the data above and half below. The table that I have made has 3 rows (which changes to 6 rows when i combine the two halves) so to make it really obvious which rows are the same i would like to add colour to emphasise it.

Here is my code to create the table (which then gets saved as a picture to appear in a document)

Mdates<-c("08Q1", "08Q2", "08Q3", "08Q4", "09Q1", "09Q2", "09Q3", "09Q4", "10Q1", "10Q2", "10Q3", "10Q4", "11Q1", "11Q2", "11Q3","11Q4", "12Q1", "12Q2", "12Q3", "12Q4", "13Q1", "13Q2", "13Q3", "13Q4", "14Q1" ,"14Q2")
Nu<-c(79160.56,  91759.73,  91186.48, 106353.82,  70346.47 , 80279.15,  82611.60, 131392.72,  93798.99, 105944.78,103913.13, 154530.69, 110157.40, 117416.09, 127423.42, 156752.00, 120097.81, 121307.75, 115021.12, 150657.83,113711.53, 115353.14, 112701.98, 154319.18, 116803.54, 118352.54)
Arimafit<-c(78272.71 , 86726.90,  90593.16, 100364.14,  81288.35,  81119.34 , 80217.01,  98878.31  ,87290.88, 106406.20,107180.51, 142035.06 ,107488.32, 124546.33, 118618.58, 175973.84, 113719.50 ,131377.98, 126586.05, 155147.44, 110674.34, 121228.03, 116329.86, 149380.53, 113957.98, 122351.76)
library(gridExtra)
png("table2.png",height=150,width=710)
tb1<-c(head(Mdates,((length(Mdates)+1)/2)),head(prettyNum(round(Nu,digits=0),big.interval=3L,big.mark=","),((length(Mdates)+1)/2)),head(prettyNum(round(Arimafit,digits=0),big.interval=3L,big.mark=","),((length(Mdates)+1)/2)))
tb2<-c(tail(Mdates,((length(Mdates)-1)/2)),tail(prettyNum(round(Nu,digits=0),big.interval=3L,big.mark=","),((length(Mdates)-1)/2)),tail(prettyNum(round(Arimafit,digits=0),big.interval=3L,big.mark=","),((length(Mdates)-1)/2)))
tb3<-matrix(c(tb1,tb2),nrow=6,byrow=TRUE)
rownames(tb3)<-c("Qtr","Actual $K","Fit $K","Qtr","Actual $k","Fit $K")
t22<-tableGrob(tb3,gp=gpar(cex=0.6))
grid.arrange(t22)
invisible(dev.off())

This is the table that appears: https://i.stack.imgur.com/pVsFr.png

I would like the colour of row1=row4, the colour of row2=row5 and the colour of row3=row6

Thankyou

Summer Gleek
  • 334
  • 5
  • 15
  • 1
    that's been asked a few times, and the short answer is no. There are a few alternatives though: using an older version, or [this experimental function](http://stackoverflow.com/questions/19934523/text-alignment-and-font-size-in-gtable/24242511#24242511) – baptiste Oct 02 '14 at 12:39

0 Answers0