Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is what I do. A darker colour indicates a more important combination of A and B.</p> <pre><code>dataset &lt;- data.frame(A = sample(LETTERS[1:5], 200, prob = runif(5), replace = TRUE), B = sample(LETTERS[1:5], 200, prob = runif(5), replace = TRUE)) Counts &lt;- as.data.frame(with(dataset, table(A, B))) library(ggplot2) ggplot(Counts, aes(x = A, y = B, fill = Freq)) + geom_tile() + scale_fill_gradient(low = "white", high = "black") </code></pre> <p>Or if you prefer lines</p> <pre><code>library(ggplot2) dataset &lt;- data.frame(A = sample(letters[1:5], 200, prob = runif(5), replace = TRUE), B = sample(letters[1:5], 200, prob = runif(5), replace = TRUE)) Counts &lt;- as.data.frame(with(dataset, table(A, B))) Counts$X &lt;- 0 Counts$Xend &lt;- 1 Counts$Y &lt;- as.numeric(Counts$A) Counts$Yend &lt;- as.numeric(Counts$B) ggplot(Counts, aes(x = X, xend = Xend, y = Y, yend = Yend, size = Freq)) + geom_segment() + scale_x_continuous(breaks = 0:1, labels = c("A", "B")) + scale_y_continuous(breaks = 1:5, labels = letters[1:5]) </code></pre> <p>This third options add labels to the data points using geom_text().</p> <pre><code>library(ggplot2) dataset &lt;- data.frame( A = sample(letters[1:5], 200, prob = runif(5), replace = TRUE), B = sample(LETTERS[20:26], 200, prob = runif(7), replace = TRUE) ) Counts &lt;- as.data.frame(with(dataset, table(A, B))) Counts$X &lt;- 0 Counts$Xend &lt;- 1 Counts$Y &lt;- as.numeric(Counts$A) Counts$Yend &lt;- as.numeric(Counts$B) ggplot(Counts, aes(x = X, xend = Xend, y = Y, yend = Yend)) + geom_segment(aes(size = Freq)) + scale_x_continuous(breaks = 0:1, labels = c("A", "B")) + scale_y_continuous(breaks = -1) + geom_text(aes(x = X, y = Y, label = A), colour = "red", size = 7, hjust = 1, vjust = 1) + geom_text(aes(x = Xend, y = Yend, label = B), colour = "red", size = 7, hjust = 0, vjust = 0) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload