Skip to content
Prev 361278 / 398506 Next

colored table

Hi Naresh

If you want to make a graphic of the table, with the frequencies printed 
in the cells try a mosaic plot from the vcd package

library(vcd)
mosaic(HairEyeColor[,,1], shade = TRUE, legend=FALSE, 
labeling=labeling_values)

or to make cell sizes proportional to expected frequencies,

mosaic(HairEyeColor[,,1], shade = TRUE, legend=FALSE, 
labeling=labeling_values, type="expected")

You can also use ggplot2::geom_tile() for something that is a more 
direct version of a table or a heatmap, with shaded backgrounds, and 
geom_text()
to print the values.

 From an non-reproducible example of mine, where cells are filled
with a unidimensional range of colors from white to blue, and
the text is printed in black, until the background gets too dark:

p <- ggplot(ht2, aes(decade, variable)) +
       geom_tile(aes(fill = Freq), color = "white") +
       scale_fill_gradient(low = "white", high = "blue") +
       geom_text(aes(fill = Freq, label = Freq),
                 colour = ifelse(ht2$Freq > 40, "white", "black")) +
       labs(title = "Keyword Occurrences by Topic and Year",
            x = "Decade", y = "Keyword")

In contrast to what someone else expressed, for some purposes --- where 
you want to show the _pattern_ of values in a table directly, colored 
backgrounds, if done judiciously can be extremely useful to show the 
viewer what is important.

-Michael
On 5/28/2016 9:10 AM, Naresh Gurbuxani wrote: