Hi all R-users, I?m trying to assign colors on those p-value in my table output that fall above a certain critical value, let?s say a p-value >0.05. My table looks like this: Assets ADF-Level P-Value ADF-First D P-Value ADF-Second D P-Value [1,] Liabilities -2.3109 0.1988 -3.162 0.025 -6.0281 0.01 [2,] Long.Bond -0.2934 0.9172 -6.1667 0.01 -7.897 0.01 [3,] Stocks -0.5539 0.8503 -5.5787 0.01 -8.9303 0.01 [4,] CPI -2.1352 0.264 -2.705 0.0794 -6.0953 0.01 [5,] Nom.10Y -2.6968 0.0807 -1.3854 0.542 -5.846 0.01 [6,] T.Bills -2.0429 0.2982 -2.2508 0.2211 -4.761 0.01 [7,] Commodities -0.3973 0.9031 -5.0478 0.01 -6.7784 0.01 [8,] Real.Estate -0.6468 0.8159 -4.8601 0.01 -8.6037 0.01 [9,] Credit.Spread 0.4181 0.9816 -3.7542 0.01 -5.9572 0.01 [10,] Term.Spread -0.6243 0.8242 -4.1885 0.01 -6.4269 0.01 [11,] Dividend.Yield 2.9316 0.99 -1.6759 0.4343 -5.1065 0.01 What could be nice was, if it is possible to highlight, for instance, all the p-values in this table that are larger than 0.05 with the color red. Any ideas on how this can be done? All the values in this table are stored in vectors that I have combined as a matrix and thereafter plotted as a matrix. Therefore this problem could also be solved if the values that are larger than 0.05 in the vector ?adf.pvalue? are saved as colored values. After the values are stored in the vectors, adf.tvalue, adf.pvalue, adf.tvalue1, adf.pvalue1, adf.tvalue2 and adf.pvalue2, the code looks like this:>output<-matrix(c(col.names,adf.tvalue,adf.pvalue,adf.tvalue1,adf.pvalue1,adf.tvalue2,adf.pvalue2),ncol=7) >colnames(output)<-c("Assets","ADF-Level","P-Value","ADF-FirstD","P-Value","ADF-Second D","P-Value")>outputThanks in advance. Sincerely, Emil -- View this message in context: http://r.789695.n4.nabble.com/Assigning-colors-on-low-p-values-in-table-tp4641395.html Sent from the R help mailing list archive at Nabble.com.
Emil, It's helpful to provide code that generates your (example) data. You can use the function dput() to do that. # I set up your matrix a bit differently than what you presented. output <- structure(c(-2.3109, -0.2934, -0.5539, -2.1352, -2.6968, -2.0429, -0.3973, -0.6468, 0.4181, -0.6243, 2.9316, 0.1988, 0.9172, 0.8503, 0.264, 0.0807, 0.2982, 0.9031, 0.8159, 0.9816, 0.8242, 0.99, -3.162, -6.1667, -5.5787, -2.705, -1.3854, -2.2508, -5.0478, -4.8601, -3.7542, -4.1885, -1.6759, 0.025, 0.01, 0.01, 0.0794, 0.542, 0.2211, 0.01, 0.01, 0.01, 0.01, 0.4343, -6.0281, -7.897, -8.9303, -6.0953, -5.846, -4.761, -6.7784, -8.6037, -5.9572, -6.4269, -5.1065, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01), .Dim = c(11L, 6L), .Dimnames = list(c("Liabilities", "Long.Bond", "Stocks", "CPI", "Nom.10Y", "T.Bills", "Commodities", "Real.Estate", "Credit.Spread", "Term.Spread", "Dividend.Yield" ), c("ADF-Level", "P-Value", "ADF-First D", "P-Value", "ADF-Second D", "P-Value"))) # here's one way to color code information in a table in a graphics device library(gplots) textplot(format(output), col.data=(output[, c(2, 2, 4, 4, 6, 6)] > 0.05)+1, halign="right") Jean Rmillan <emiln_leifsson@hotmail.com> wrote on 08/27/2012 04:05:38 AM:> > Hi all R-users, > > I?m trying to assign colors on those p-value in my table output thatfall> above a certain critical value, let?s say a p-value >0.05. > My table looks like this: > > Assets ADF-Level P-Value > ADF-First D P-Value ADF-Second D P-Value > [1,] Liabilities -2.3109 0.1988 > -3.162 > 0.025 -6.0281 0.01 > [2,] Long.Bond -0.2934 0.9172 -6.1667 > 0.01 -7.897 > 0.01 > [3,] Stocks -0.5539 0.8503 -5. > 5787 > 0.01 -8.9303 0.01 > [4,] CPI -2.1352 0.264 -2.705 > 0.0794 -6.0953 0.01 > [5,] Nom.10Y -2.6968 0.0807 -1. > 3854 > 0.542 -5.846 0.01 > [6,] T.Bills -2.0429 0.2982 -2. > 2508 > 0.2211 -4.761 0.01 > [7,] Commodities -0.3973 0.9031 -5.0478 > 0.01 -6.7784 > 0.01 > [8,] Real.Estate -0.6468 0.8159 -4.8601 > 0.01 -8.6037 > 0.01 > [9,] Credit.Spread 0.4181 0.9816 -3.7542 > 0.01 -5.9572 > 0.01 > [10,] Term.Spread -0.6243 0.8242 -4.1885 > 0.01 -6.4269 > 0.01 > [11,] Dividend.Yield 2.9316 0.99 -1.6759 0.4343 > -5.1065 0.01 > > What could be nice was, if it is possible to highlight, for instance,all> the p-values in this table that are larger than 0.05 with the color red. > Any ideas on how this can be done? > > All the values in this table are stored in vectors that I have combinedas a> matrix and thereafter plotted as a matrix. Therefore this problem > could also be solved if the values that are larger than 0.05 in thevector> ?adf.pvalue? are saved as colored values. > After the values are stored in the vectors, adf.tvalue, adf.pvalue, > adf.tvalue1, adf.pvalue1, adf.tvalue2 and adf.pvalue2, the code lookslike> this: > > >output<-matrix(c >(col.names,adf.tvalue,adf.pvalue,adf.tvalue1,adf.pvalue1,adf.tvalue2,adf.pvalue2),ncol=7)> >colnames(output)<-c("Assets","ADF-Level","P-Value","ADF-First > D","P-Value","ADF-Second D","P-Value") > >output > > Thanks in advance. > > Sincerely, > > Emil[[alternative HTML version deleted]]
On 08/27/2012 07:05 PM, Rmillan wrote:> Hi all R-users, > > I?m trying to assign colors on those p-value in my table output that fall > above a certain critical value, let?s say a p-value>0.05. > My table looks like this: > ...Here is the data frame I used: returns Assets ADF_Level P0 ADF_First P1 ADF_Second P2 1 Liabilities -2.3109 0.1988 -3.1620 0.0250 -6.0281 0.01 2 Long.Bond -0.2934 0.9172 -6.1667 0.0100 -7.8970 0.01 3 Stocks -0.5539 0.8503 -5.5787 0.0100 -8.9303 0.01 4 CPI -2.1352 0.2640 -2.7050 0.0794 -6.0953 0.01 5 Nom.10Y -2.6968 0.0807 -1.3854 0.5420 -5.8460 0.01 6 T.Bills -2.0429 0.2982 -2.2508 0.2211 -4.7610 0.01 7 Commodities -0.3973 0.9031 -5.0478 0.0100 -6.7784 0.01 8 Real.Estate -0.6468 0.8159 -4.8601 0.0100 -8.6037 0.01 9 Credit.Spread 0.4181 0.9816 -3.7542 0.0100 -5.9572 0.01 10 Term.Spread -0.6243 0.8242 -4.1885 0.0100 -6.4269 0.01 11 Dividend.Yield 2.9316 0.9900 -1.6759 0.4343 -5.1065 0.01> What could be nice was, if it is possible to highlight, for instance, all > the p-values in this table that are larger than 0.05 with the color red. > Any ideas on how this can be done? >Hi Emil, Try this: library(plotrix) retcol<-cbind(rep(NA,11),ifelse(returns[,"P0"]>0.05,"red",NA), rep(NA,11),ifelse(returns[,"P1"]>0.05,"red",NA), rep(NA,11),ifelse(returns[,"P2"]>0.05,"red",NA)) plot(1:10,type="n",axes=FALSE,xlab="",ylab="") addtable2plot(1,9,returns[,-1],bg=retcol) Jim