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

Several questions, and request (and offer) for documentation update #89

Closed
quinnj opened this issue Oct 20, 2013 · 9 comments
Closed

Several questions, and request (and offer) for documentation update #89

quinnj opened this issue Oct 20, 2013 · 9 comments

Comments

@quinnj
Copy link

quinnj commented Oct 20, 2013

Hey @dcjones,

I've recently gotten into the world of graphics in Julia (I avoided them for quite a while so things could develop....), but I'm now up and running in IJulia and giving the various packages a spin. My initial taking has been with Gadfly, but I've also run into quite a few questions and hope you can help. I'd also be willing to help flesh out documentation as I continue to learn if that would help.

  1. If I'm trying to add multiple lines to a graph, the recommended way is through plot(data,layer(), layer() correct?
  2. Related, if I'm using more than one Geom.line layer, can that be detected and different colors be used for the lines? It's just not that helpful to be able to have multiple lines, but a single color
  3. Related, what about adding another line with a "secondary axis", meaning the y-axis on the left would be the scale for one line, while the 2nd y-axis on the right would be the scale for the other line.
  4. When splitting plots into 2 via hstack/vstack, it seems like I can't get the plots to size correctly, like they're ignoring the default_plot_size I set for the single graph. Is there a way to fix that? Or is using subplot_grid the recommended way?

Thanks!

@dcjones
Copy link
Collaborator

dcjones commented Oct 20, 2013

  1. (and 2) The most common way to draw multiple lines is to bind color to some discrete data of the same length as x and y. The second example here is what that looks like. (By the way, that's also an example of a kludgy plot that would be much better with proper support for date and time types.)

    Generally it's best to coerce the data you are plotting into that pattern. Plotting data frames is nice, since the data is already columns of equal length. It is also possible to make multiple layers each with a different Theme, but I haven't provided a very convenient way to do that.

  2. There's not currently a way to plot two lines on different scales sharing the same panel. It wouldn't be hugely difficult to implement this as a special geometry sort of like Geom.subplot_grid. I'll make a note to do that, but it's not my highest priority right now.

  3. vstack/hstack is a way to stick together two unrelated plots, and subplot_grid is a way to draw the same sort of plot on different subsets of the data. Personally, I try to use subplot_grid. It's more automatic, but it's also maybe less obvious how it works.

    I'm not sure what's going on with the size, it certainly could be a bug.

I'd definitely welcome additions to the documentation, or even pointing out what doesn't make sense. It's all in markdown files in the doc directory. The html is generated using a somewhat incomplete, half-baked documentation system.

@msimberg
Copy link

msimberg commented Dec 1, 2013

Hi, I'm really liking Gadfly so far! Could you maybe point me in the direction of how to make multiple layers each with a different theme, I couldn't find even the inconvenient way you mentioned anywhere in the manual? You seem to prefer to have everything in one dataframe, but I don't think that should be the only way because it can get pretty clunky in some cases (and sure, layers solve it partly, but not regarding themes). With separate themes for each layer one could potentially manually choose colors and eventually different line styles. I would expect something like this working

l1 = layer(x=..., y=..., Theme(...))
l2 = layer(x=..., y=..., Theme(...))
plot(l1, l2)

but right now it seems like you can only put Theme() as an argument directly to plot which obviously gives the same style to all layers. Really appreciate what you're doing with Gadfly!

@msimberg
Copy link

msimberg commented Dec 1, 2013

Alternatively, I just noticed that Geom.hline and Geom.vline both take a color keyword argument --- would it be possible to implement a similar feature for Geom.line as well? Maybe line style could be implemented there as a keyword argument as well instead of making for example a new Geom.dashedline?

@dcjones
Copy link
Collaborator

dcjones commented Dec 3, 2013

Hi @msimberg. I've made an update that lets you pass theme objects to layers, so you should be able to use the syntax your were expecting now.

One goal with Gadfly is to have a clear separation between defining the visualization in terms of the data and modifying low-level details of how it's drawn (like assigning specific colors to specific lines). I violated that a little in the name of convenience with the arguments to hline/vline and I want to try to avoid that sort of thing in general.

I do understand that if the data you're plotting isn't in one data frame it can be awkward to use Gadfly as it was intended, and I want to try to improve that. What I'm thinking of is adding a syntax sort of like this:

x1 = [1, 2, 3]
y1 = [2, 4, 8]
x2 = [1, 2, 3]
y2 = [3, 9, 27]

# draw two lines without manually building a data frame
plot(x=(x1, x2), y=(y1, y2), color=["squares", "cubes"], Geom.line)

Anyway, changing colors by setting per-layer themes is fine, but there should eventually exist a nicer way of doing things.

@msimberg
Copy link

msimberg commented Dec 3, 2013

Thanks @dcjones! Design decisions are obviously up to you and I'm happy with this because it does what I need.

Not necessarily an issue (and certainly not for me) but I noticed that layer requires some Geom object unlike plot, otherwise it draws a blank figure. Don't know if this is intended or not.

@quinnj
Copy link
Author

quinnj commented Dec 3, 2013

+1 for being able to plot multiple lines from separate arrays/dfs.

@msimberg
Copy link

msimberg commented Dec 8, 2013

@dcjones So I was testing around a bit more, and while different themes in different layers works fine now, it's not now possible to get a legend for the different layers (unless I've missed some documentation on legends?) and I think that is really needed. In this regard dataframes are really nice, since you kind of get the right legend for free. If you end up implementing some kind of syntax like the one you proposed (or any syntax that explicitly specifies several lines) then it should also be possible to define a legend for them. I don't know what a reasonable way to do this would be though. Maybe I just need to accept having to use dataframes, but as you seem to agree they're not always the most convenient way to do things.

@gibiansky
Copy link

It would be really nice if we could add legends for layers. It's either impossible or not documented, but using color is really annoying, so it'd be nice to be able to add a custom legend...

@TripleDogDare
Copy link

This is old but, for question of customized legends. You can use something like the following:

color_arr = [color("orange") color("blue")]
plot( dataframe,
    layer( x=:X_Symbol, y=:Y_Symbol, Geom.line, color=["Series Label"],
    layer( x=:X_Symbol2, y=:Y_Symbol2, Geom.line, color=["Series Label 2"],
    Scale.discrete_color_manual(color_arr...)
)

Related to vstack/hstack, I'd like to plot 3 plots in a grid where each plot is the same size.
I.E. Something like this

   []
[] [] 

Or maybe doing 8 plots with a hole in the middle.

[] [] []
[]    []
[] [] []

Currently vstack/hstack will create a plot that expands into any unused space so that one of the plots will be larger than the others. I've been looking at trying to make a blank plot or context, but the render function chokes on it. Is there a way to do this at all?

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

6 participants