Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to deal with 2D data / heatmaps? #267

Open
tbenst opened this issue Aug 19, 2021 · 3 comments
Open

how to deal with 2D data / heatmaps? #267

tbenst opened this issue Aug 19, 2021 · 3 comments

Comments

@tbenst
Copy link

tbenst commented Aug 19, 2021

This is less an AOG issue than a general irk with grammar of graphics. Dealing with 2D data is a bit unwieldly.

matrix = rand(100,100)
matrix_df = DataFrame(matrix, string.(collect(1:size(matrix,2))))
matrix_df[!,:y] = 1:size(matrix,1)
matrix_df = stack(matrix_df, 1:size(matrix,2))
rename!(matrix_df, :variable => :x)
matrix_df[!, :x] = parse.(Int,matrix_df[!, :x])
matrix_df
p = data(matrix_df)  * mapping(:x, :y, :value) * visual(Heatmap) |> draw

is a lot of work compared to:

using Plots
matrix = rand(100,100)
heatmap(matrix)
@piever
Copy link
Collaborator

piever commented Aug 19, 2021

You are not forced to have your data in a table in AoG, so for example with the "pre-grouped" syntax (see #212 (comment) and http://juliaplots.org/AlgebraOfGraphics.jl/dev/gallery/gallery/data%20manipulations/pre_grouped_data/#Pre-grouped-data), you could do

x, y, z = 1:10, 1:10, rand(10, 10)
mapping([x] => "x", [y] => "y", [z] => "z") * visual(Heatmap) |> draw

Ideally all the possible syntaxes (basically there are the 4 combinations of pre-grouped vs not pre-grouped and with a dataset vs without a dataset) should be supported easily. For now only pre-grouped without dataset and not pre-grouped with dataset are supported, but hopefully it should be easier to get all of them to work. Heatmap (or in general these plots with 2-d data) are definitely a good use cases for that).

@tbenst
Copy link
Author

tbenst commented Aug 19, 2021

That’s awesome! Thank you. Might I suggest that the simple example you just posted be added to the pre-grouped documentation? It’s very ergonomic and I didn’t gather that was possible until your kind reply

@rashidrafeek
Copy link

The above example doesn't work now. mapping has to be replaced with pregrouped for the same effect now:

x, y, z = 1:10, 1:10, rand(10, 10)
pregrouped([x] => "x", [y] => "y", [z] => "z") * visual(Heatmap) |> draw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants