问题
I have a very simple problem. I have a data frame with multiple rows and columns. My rows represents points in time. My columns are potential conditions and my cells are the probabilities that those conditions occurred at a specfic time.
I would like to take this information and output to a PDF table. Additionally, I'd like to add coloring to this. For example < 60% grey text. 60-75 green text. 75+ bright green.
Is there anyway to do this?
Additionally, would it be possible to have one column in my PDF output which consists of horizontal bars. The size of the bars would be based on my cell values as well. Ideally, I could apply coloring to this as well.
回答1:
If you are willing to use LaTeX you could use Rd2roxygen, there is a range of ways to export tables from R to LaTeX or HTML.
If you do not want to use LaTeX you might be able to communicate the difference in your cells by using a heat map. Here is a nice example by Jason Bryer and another example.
Table from Jason Bryer's blog for the ones who do not have the time to clink the link above.

回答2:
Went with ggplot and a heatmap.
Sample code below.
df.m = melt(df)
df.m <- ddply(df.m, .(variable), transform,rescale = scale(value))
pp = ggplot(df.m, aes(x = variable, y = Time, fill = rescale, label = sprintf("%1.1f%%", 100*value),size=10))
pp = pp + geom_tile() + geom_text(aes(size=10)) +
scale_x_discrete(name = '', expand = c(0, 0)) +
scale_y_discrete(name = '', expand = c(0, 0)) +
scale_fill_gradient2(low = 'grey', high = 'steelblue') +
theme_bw() +
opts(legend.position = 'none',
panel.grid.major = theme_line(colour = NA),
panel.grid.minor = theme_line(colour = NA))
来源:https://stackoverflow.com/questions/10098856/data-frame-to-pdf-html-table-with-colored-text