is it possible to do the following:
loc1 <- c("Aa", "Aa", "aa", "Aa")
loc2 <- c("aa", "aa", "aa", "AA")
loc3 <- c("aa", "Aa", "aa", "aa")
gen <- data.frame(loc1, loc2, loc3)
loc1g <- c(0.01, 0.5, 1, 0.75)
loc2g <- c(0.2, 0.1, 0.2, 0.6)
loc3g <- c(0.8, 0.8, 0.55, 1)
pval <- data.frame(loc1g, loc2g, loc3g)
I want to print to a file to gen dataframe such way that is conditionally formatted by the pval dataframe. Means than (row1, col1) of gen color depends upon pvale (row1, col1). The following are color coding:
0 to 0.3 is "red" text color
0.31 to 0.7 is "yellow"
> 0.7 is "red"
gen[1,1] will be “Aa” printed in red text color and so on….
appreciated your help.
EDITS:
I am more interested in printing not plotting in graph. If I can save output as MS excel and open in MSEXCEL it would be great. I can also be other types of text editors format that can read color coded text. As my orginal data matrix should be of a dimension of 1000 x 1000 or even more. I would like to quicky know unlying p-value for each gen categories.
Giving a POC-like answer which is using an ugly loop and not the most beatiful design:
Loading eg. the
xlxspackage to be able to write to Excel 2007 format:Let us create a workbook and a sheet (see the manual!):
Define some styles to use in the spreadsheet:
And the ugly loop which is pasting each cell to the spreadsheet with appropriate format:
Saving the Excel file:
Result: demo.xls
Alternative solution with package
ascii:ascii.data.frame()can export data frames to a bunch of formats with the ability of adding some formatting. E.g. exporting to pandoc, first define the styles of each cells to an array with the same dimensions aspval:Set the desired output:
And export the data frame:
With
ascii::Reportyou could easily convert it it pdf, odt or html. Just try it 🙂 Small demo with HTML output: resultAnd odt output: result