mirror of
https://gitlab.com/MisterBiggs/splomplots.jl.git
synced 2025-06-16 14:36:39 +00:00
added legend, custom columns
This commit is contained in:
parent
4853ad51e4
commit
b268b295e3
@ -4,18 +4,23 @@ using DataFrames
|
|||||||
using Plots
|
using Plots
|
||||||
using RDatasets
|
using RDatasets
|
||||||
|
|
||||||
function splom(df::DataFrame)
|
function splom(df::DataFrame; group="", columns=[])
|
||||||
columns = Dict(names(df) .=> eltype.(eachcol(df)))
|
if columns == []
|
||||||
|
columns = Dict(names(df) .=> eltype.(eachcol(df)))
|
||||||
for (key, value) in columns
|
else
|
||||||
if value <: Number
|
columns = Dict(names(df[!,columns]) .=> eltype.(eachcol(df[!,columns])))
|
||||||
continue
|
|
||||||
|
|
||||||
else
|
|
||||||
pop!(columns, key)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for (key, value) in columns
|
||||||
|
if value <: Number
|
||||||
|
continue
|
||||||
|
|
||||||
|
else
|
||||||
|
pop!(columns, key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
println(columns)
|
||||||
cols = collect(keys(columns))
|
cols = collect(keys(columns))
|
||||||
col_pairs = [(x, y) for x in cols, y in cols]
|
col_pairs = [(x, y) for x in cols, y in cols]
|
||||||
col_len = length(cols)
|
col_len = length(cols)
|
||||||
@ -25,12 +30,38 @@ function splom(df::DataFrame)
|
|||||||
|
|
||||||
for (i, (x, y)) in enumerate(col_pairs)
|
for (i, (x, y)) in enumerate(col_pairs)
|
||||||
scatter_plots[i] = plot()
|
scatter_plots[i] = plot()
|
||||||
|
|
||||||
if x == y
|
if x == y
|
||||||
plot!(;
|
if i == col_len^2 && group != ""
|
||||||
xaxis=nothing, yaxis=nothing, showaxis=false
|
fakedat = (1:length(df[!, x])) .* 0
|
||||||
)
|
scatter!(
|
||||||
|
fakedat,
|
||||||
|
fakedat;
|
||||||
|
xaxis=nothing,
|
||||||
|
yaxis=nothing,
|
||||||
|
showaxis=false,
|
||||||
|
grid=false,
|
||||||
|
xlims=(1, 0),
|
||||||
|
ylims=(1, 0),
|
||||||
|
group=df[!, group],
|
||||||
|
legend=:topleft,
|
||||||
|
)
|
||||||
|
else
|
||||||
|
plot!(;
|
||||||
|
xaxis=nothing,
|
||||||
|
yaxis=nothing,
|
||||||
|
showaxis=false,
|
||||||
|
)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
scatter!(df[!, x], df[!, y])
|
scatter!(
|
||||||
|
df[!, x],
|
||||||
|
df[!, y];
|
||||||
|
group=df.Species,
|
||||||
|
label="",
|
||||||
|
)
|
||||||
|
|
||||||
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
if i % col_len == 1
|
if i % col_len == 1
|
||||||
@ -42,11 +73,11 @@ function splom(df::DataFrame)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return plot(scatter_plots...; label="")
|
return plot(scatter_plots...;)
|
||||||
end
|
end
|
||||||
|
|
||||||
df = dataset("datasets", "iris")
|
df = dataset("datasets", "iris")
|
||||||
|
|
||||||
splom(df)
|
splom(df; group=:Species,columns=[:SepalLength, :SepalWidth, :PetalWidth])
|
||||||
|
|
||||||
end # module
|
end # module
|
||||||
|
Loading…
x
Reference in New Issue
Block a user