using DataFrames, FreqTables, NamedArrays
using Plots
gr(size=(400, 300)); # as you like
# Heatmap difinition for pivot
Plots.heatmap(pivot::NamedArray)= heatmap(names(pivot)..., pivot.array')
df = DataFrame(Location = ["NY", "SF", "NY", "NY", "SF", "SF", "TX", "TX", "TX", "DC", "DC", "DC"],
Class = ["M","M","H","L","L","H", "H","L","M","M","H","L"],
Score = rand(12))
Location | Class | Score | |
---|---|---|---|
String | String | Float64 | |
1 | NY | M | 0.297741 |
2 | SF | M | 0.97259 |
3 | NY | H | 0.280303 |
4 | NY | L | 0.881094 |
5 | SF | L | 0.951233 |
6 | SF | H | 0.25687 |
7 | TX | H | 0.541418 |
8 | TX | L | 0.293883 |
9 | TX | M | 0.0366796 |
10 | DC | M | 0.169236 |
11 | DC | H | 0.575508 |
12 | DC | L | 0.51283 |
pivot = freqtable(df, :Location, :Class, weights=df.Score)
4×3 Named Array{Float64,2} Location ╲ Class │ H L M ─────────────────┼──────────────────────────────── DC │ 0.575508 0.51283 0.169236 NY │ 0.280303 0.881094 0.297741 SF │ 0.25687 0.951233 0.97259 TX │ 0.541418 0.293883 0.0366796
heatmap(pivot)