3
$\begingroup$

I'm a hobbyist programmer whose friend recently took a business trip overseas. He's polled our mutual friends for bets on the size of his email inbox when he returns. I'd like to visualize this as a one-dimensional heatmap where color reflects a kind of density of guesses for that value. I understand I could create a histogram and find a way to translate its values into color values. However, the histogram bins would create janky transitions in color. Is there a way to create an appropriate, continuous function for prettier output?

$\endgroup$

1 Answer 1

6
$\begingroup$

Use density and fields::colorbar.plot

require(fields)
plot(1:10, rep(1,10), ylim=c(0,10))
 colorbar.plot( 2, 4, 800*density(rgamma(100, shape=2))$y)
 colorbar.plot( 2, 5, 800*density(rexp(100))$y)
 colorbar.plot( 2, 6, 800*density(rnorm(100))$y)
 colorbar.plot( 2, 7, 800*density(rlnorm(100))$y)
 text(6,4, "Gamma")
 text(6,5, "Exponential")
 text(6,6, "Normal")
 text(6,7, "LogNormal")

enter image description here

$\endgroup$
3
  • $\begingroup$ What programming language/system is this? $\endgroup$
    – ldrg
    Commented Oct 25, 2011 at 3:14
  • $\begingroup$ This is done in R. I just assumed anyone who wanted a heatmap would be using R or S, since none of the statistical languages I worked with in the past had that facility, but I guess they may have caught up if your expectation was to get a heatmap implemented in another language. $\endgroup$
    – DWin
    Commented Oct 25, 2011 at 12:28
  • 1
    $\begingroup$ The rainbow/jet colormap is generally a bad idea. jwave.vt.edu/~rkriz/Projects/create_color_table/color_07.pdf $\endgroup$
    – endolith
    Commented May 30, 2012 at 23:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.