Skip to content

Instantly share code, notes, and snippets.

@aviatesk
Created April 22, 2020 13:35
Show Gist options
  • Save aviatesk/addac4484f8f455f4bf5ad14ef137eb0 to your computer and use it in GitHub Desktop.
Save aviatesk/addac4484f8f455f4bf5ad14ef137eb0 to your computer and use it in GitHub Desktop.
plotting `@linq` chain
using DataFrames, DataFramesMeta, Plots, StatsPlots, StatsBase
# HACK:
# integrate StatsPlots.@df into @linq chain in a way data frame keeps to be passed even after plot
# but, the `names` part might be too dangerous
for n in names(StatsPlots)
function DataFramesMeta.linq(::DataFramesMeta.SymbolParameter{n}, d, args...)
plotcall = Expr(:call, n, args...)
return quote let d = $d
display(@df d $plotcall)
d
end end
end
end
@linq DataFrame(name = rand('A':'Z', 1000), val = rand(1000)) |>
by(:name, mean = mean(:val)) |>
sort(:name) |>
bar(:name, :mean; orientation = :horizontal) |>
transform(meanall = fill(mean(:mean), length(:mean))) |>
vline!(:meanall)
@aviatesk
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment