title: R heatmap newbie: plot pair counts
body: <p>I need to create a heatmap showing distinct (charCount, wordCount) pair counts (where <code>charCount</code> is a number of chars and <code>wordCount</code> is a number of words in text abstracts).
  As input I have a csv file where each line has two numbers: <code>charCount</code> and <code>wordCount</code>. I can read this into matrix and then plot heatmap:</p>
  
  <pre><code>data = read.csv("chars_words.txt", sep=",", header=FALSE)
  mtx &lt;- as.matrix(data)
  heatmap(mtx)
  </code></pre>
  
  <p>Yet for the following data:</p>
  
  <pre><code>charCount, wordCount
  1000,100
  1000,100
  1000,100
  900,90
  800,80
  700,70
  600,60
  500,50
  300,30
  200,20
  100,10​
  </code></pre>
  
  <p>I get a plot of two colors only. How can I create a plot showing distinct (charCount, wordCount) pair counts with color?</p>
  
  <p>*** Update 2:</p>
  
  <p>This code from <a href="https://stackoverflow.com/users/4964651/mtoto">moto</a> solves my problem:</p>
  
  <pre><code>library(ggplot2)
  library(dplyr)
  
  # Convert your data into frequency matrix, then data.frame
  df&lt;-data.frame(table(data))
  
  # Set columns ready for ggplot
  df$Freq&lt;-as.factor(df$Freq)
  df$charCount&lt;-as.character(df$charCount) %&gt;% as.numeric()
  df$wordCount&lt;-as.character(df$wordCount) %&gt;% as.numeric()
  
  # plot using ggplot
  ggplot(df,aes(x=charCount,y=wordCount)) +
  geom_tile(aes(fill=Freq)) +
  geom_text(aes(label=Freq))
  </code></pre>
  
  <p>Which results in a nice plot (example data, not from original task):</p>
  
  <p><a href="https://i.stack.imgur.com/strYu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/strYu.png" alt="Pair Distribution"></a></p>