Skip to content

Instantly share code, notes, and snippets.

@jkrumbiegel
Created January 17, 2020 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkrumbiegel/a322614cf7e5661e14d5b3fbbc6ffbf6 to your computer and use it in GitHub Desktop.
Save jkrumbiegel/a322614cf7e5661e14d5b3fbbc6ffbf6 to your computer and use it in GitHub Desktop.
Iris MakieLayout corrplot
using Makie, MakieLayout, AbstractPlotting, Statistics, StatsMakie, StatsBase, RDatasets
@recipe(CorrLayout) do scene
Theme(
markersize = 5 * AbstractPlotting.px
)
end
function AbstractPlotting.plot!(scene::Scene, ::Type{CorrLayout}, attributes::Attributes, mat)
n = size(mat, 2)
C = cor(mat)
layout = GridLayout(n, n)
layout[1:n, 1:n] = axs = [LAxis(scene) for i in 1:n, j in 1:n]
for i in 1:n, j in 1:n
vi = view(mat, :, i)
vj = view(mat, :, j)
ax = axs[i, j]
# s = Scene(scene, Reactive.value(pixelarea(scene)))
if i == j # histograms are on the diagonal
histresult = fit(Histogram, vi)
barplot!(ax, midpoints(histresult.edges[1]), histresult.weights)
elseif i > j
scatter!(ax, vj, vi, markersize = attributes[:markersize])
else
scatter!(ax, vj, vi, markersize = attributes[:markersize])
end
end
scene, axs, layout
end
data = RDatasets.dataset("datasets", "iris")
mat = Matrix(data[!, 1:4])
##
scene, layout = layoutscene()
_, axs, sublayout = corrlayout!(scene, mat; markersize = 5 * AbstractPlotting.px)
layout[1, 1] = sublayout
scene
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment