Sometimes it is needed to draw categorical values on a regular grid to show how they cover a certain area. In principle, the plot() function is a good fit for this, but there is a problem that is needed to adjust the size of the icons each time to create the illusion of a solid cover. When changing the coverage of the image, the old size becomes irrelevant and is needed to adjust it again. Is there a technique to adjust this size automatically?
using Plots
using CategoricalArrays
a = [1, 2, 3, 1, 2, 3, 1, 2, 3]
b = [1, 1, 1, 2, 2, 2, 3, 3, 3]
c = CategoricalArray(["X", "X", "Y", "Z", "Y", "Y", "Z", "Y", "Z"])
plot(a, b, group = c, seriestype = :scatter, aspect_ratio = 1, markersize=90,
markershape=:square, markerstrokewidth=0.0, xlim = (0.5, 3.5), ylim = (0.5, 3.5))
The result is good in everything, except that each time you need to adjust the size of the cells so that there are no overlapping areas or gaps:
As an alternative, I considered heatmap(), but it works quite strangely with categorical data, setting them some kind of scale of its own with a continuous gradation of values. I haven't come across any examples where using heatmap() would get a map with a beautiful legend like plot(), so I'm not sure that using heatmap() is the right way here.
a = b = [1, 2, 3]
c = CategoricalArray(["X" "X" "Y"; "Z" "Y" "Y"; "Z" "Y" "Z"])
heatmap(a, b, c)
Maybe there is still some way to automatically set the size of the cells of plot()?



