# Load ggplot2. Use install.packages("ggplot2") if you do not already have ggplot2 installed.
library(ggplot2)
# Load the diamonds dataset.
data(diamonds)
# Look at a few rows of the relevant columns
diamonds[1:20,2:3]
# Display the contingency table
table(diamonds$cut,diamonds$color)
# Make the fluctuation plot
ggfluctuation(table(diamonds$cut,diamonds$color))
The table looks like this:
D E F G H I J
Fair 163 224 312 314 303 175 119
Good 662 933 909 871 702 522 307
Very Good 1513 2400 2164 2299 1824 1204 678
Premium 1603 2337 2331 2924 2360 1428 808
Ideal 2834 3903 3826 4884 3115 2093 896
And the plot:
As a side note, I'm experimenting with a new way to post R code. If you hover your mouse over the code above you can click this button to copy all the text to your clipboard.