Comments (7)
To make the discussion more complete, here is an example of a simplified @with
macro called @given
:
macro given(d, x)
esc(_given(d,x))
end
_given(d, x) = x
function _given(d, x::Expr)
(x.head == :quote) && return :(haskey($d, $x) ? $d[$x] : $x)
(x.head == :call) && x.args[1] == :^ && length(x.args) == 2 && return x.args[2]
return Expr(x.head, _given.(d, x.args)...)
end
Usage:
using StatPlots, DataFrames,RDatasets
iris = RDatasets.dataset("datasets","iris")
@given iris scatter(:PetalLength, :PetalWidth, group = :Species, legend = :topleft)
iris[:topleft] = rand(150)
@given iris scatter(:SepalLength, :SepalWidth, group = :Species, legend = ^(:topleft))
Advantages over @with
:
- No need to escape the symbols unless there actually is ambiguity
- No DataFramesMeta dependency
- It's easy to adjust it to include other datasources, provided they allow extracting one column (which I'm assuming all of them do)
from statsplots.jl.
I am sure I had written this already here, but apparently I forgot to post it: as a first non-breaking step, if there is consensus, I'd be happy to make a PR with the @given
macro, mentioning it instead of @with
in the README. Of course we should maybe spend some time figuring out what's the best name for @given
.
Even if we get the plot(df,...)
syntax to work, it's good to also have the macro version because it retains some advantages that are just impossible to achieve with a function:
- Manipulating columns doesn't require wrapping everything in a
:()
. For example one can write
@given iris scatter(log.(:PetalLength), :PetalWidth .+ 1, group = :SepalWidth .> 3, legend = :topleft)
and it would just work (I'm even tempted to add a where
kw to also select what data to plot in the plot command)
- Manipulating columns doesn't require a runtime
eval
@mkborregaard : what's your take on this?
from statsplots.jl.
Sorry for not responding - I'm reading and thinking carefully but haven't had a chance to do it justice - please have a little patience :-)
from statsplots.jl.
My gut reaction is that adding additional syntax would be unfortunate given the goals of the Plots.jl
ecosystem. Then again, the functionality is more important, and if this would fix some of the issues with using DataFrames to their full extent...
Alas, I don't understand enough of the backend stuff to comment on implementation.
from statsplots.jl.
I think this looks really cool. It's certainly a lot simpler than the current non-macro framework!! If you'd make a PR with the given macro I'll try it out in some of the other cases I've been considering. This involves e.g. passing a part of a DataFrame as a matrix but that should be possible with [:a :b]
here I think.
I think we should be sure to be compatible not just with DataFrames but with abstract table formats such as DataTables, JuliaDB, IndexedTables etc but I'll need to check the current status of those to see if that could work.
Another thing I'd like the macro to do was to replace all NAs with NaNs for number fields, and "" / Symbol() for string/symbol fields, so that the plot function doesn't automatically fail when passing it a DataFrame with NAs in it.
In short, I agree that a macro approach is the best way to deal with table symbols.
from statsplots.jl.
Your intuition is correct, using the horizontal concatenation syntax:
@given iris corrplot([:SepalLength :SepalWidth :PetalLength :PetalWidth])
I'll add the missing value part and make a PR tomorrow.
As for the support of any table-like structure, maybe the easiest is to support IterableTables
? I'm also not sure what the state of affairs is in the data echosystem...
from statsplots.jl.
This should be fully resolved now.
from statsplots.jl.
Related Issues (20)
- invalid image url for "Dendrogram on the right side"
- ytick doesn't show all ticks
- Documentation of StatsPlots.jl is in Plots.jl repo? HOT 1
- Raincloud Plots HOT 3
- Removing dependency on DataValues.jl
- `groupedhist` and `groupedbar` `ylims` not working when x and y axis switched.
- Bugs in `cornerplot` and `corrplot` HOT 2
- How to specify fillcolor for violin plots? HOT 1
- The broadcast pipe operator doesn't get recognized by the @df macro
- kwagrs splatting does not work for errorline
- Feature request: support for percentograms HOT 1
- Plot of ecdf with groups gives incorrect plot HOT 3
- errorline! does not work with Dates x-axis
- julia 1.9.4 crashes with corrplot >11 columns HOT 2
- Line breaks when using @df macro with missing data
- New release HOT 1
- Feature Request: Automatically set default xlabel and ylabel given the column names
- Example "ordination" in readme.md doesn't works
- `xformatter` has no effect in `groupedbar()` when `x`, `y`, and `group` are provided
- Barplot colors not working with PGFPlotsX backend
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from statsplots.jl.