johnmyleswhite / Vega.jl

A Julia package for generating visualizations in Vega
Other
84 stars 22 forks source link

Convenient Syntax to express grammars #4

Closed lindahua closed 9 years ago

lindahua commented 11 years ago

I am really excited about Vega. This is a framework that is user friendly and expressive.

What remains needed is a way to express the grammar that really unlocks the power of this grammatical system (just like ggplot2).

Considering the plot in http://trifacta.github.io/vega/editor/ (the scatter plot)

it would be nice to be able to express that as

vgplot(x=:sepalWidth, y=:pedalLength, data=iris, width=200, height=200) 
+ xaxis(ticks=5, title="Sepal width")    # specify properties of x-axis
+ yaxis(ticks=5, title="Pedal length")   # specify properties of y-axis
+ points(fill=:species, opacity=0.5)      # use points (symbols) as marks 
+ legend(title="species") 

Here, vgplot is similar to ggplot in ggplot2 of R. Also, these xaxis, yaxis, points and legend should be optional. If they are not specified, the function should have a reasonable default behavior.

johnmyleswhite commented 11 years ago

Glad you're liking

I actually started doing this and then stopped since I wasn't sure if the ggplot2 interface is appropriate: https://github.com/johnmyleswhite/VGPlot.jl

I'm right in the middle of rewriting the types used in Vega.j to avoid code duplication, which will make it easier to track changes to the raw Vega library's types. That work should be done midweek, after which I'll try tackling the grammar-style interface once again.

randyzwitch commented 9 years ago

I'm going to close this. I've reached reasonable feature parity with the Python Vincent library, and the Julia code has become very Pythonic along the way. As of now, each visualization has very few keyword arguments, then I'm creating mutating functions for the behaviors like so:

using Vega

x = [0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9]
y = [28, 43, 81, 19, 52, 24, 87, 17, 68, 49, 55, 91, 53, 87, 48, 49, 66, 27, 16, 15]
g = [0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1]

b = barplot(x = x, y = y, group = g, stacked = true)
colorscheme!(b, ("Greens", 3))

As it is, I'm not really a fan of the gg syntax, as theoretically sound as it might be.

johnmyleswhite commented 9 years ago

Good call. Shrinking the scope of this package is a good way to go.