10

Is there currently a way to add plot elements together in Gadfly.jl?

For example, in R if I have another function that returns a ggplot and I want to add a title to it, I'd do the following:

p <- makeMyPlot()
p + ggtitle("Now it has a title")

Is there currently a Gadfly equivalent? If not, is this on Gadfly's roadmap?

Jeremy Wall
  • 23,907
  • 5
  • 55
  • 73
Ben Hamner
  • 4,575
  • 4
  • 30
  • 50

1 Answers1

11

There is add_plot_element(), which can add stuff to an existing layer:

xs = [0:0.1:pi]
l = layer(x=xs, y=sin(xs))
add_plot_element(l, Guide.title("Now it has a title"))

You can then plot the layer using plot(l), and invoke either draw or display to actually show something. Further down, there's a bunch of overloads that work on a Plot directly:

p = plot(x=xs, y=sin(xs))
add_plot_element(p, Guide.title("Now it has a title"))
display(p)

I can't find either of these functions in the documentation, but fortunately the source is comprehensible enough. One of the many joys of Julia =)

Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
  • I just got a downvote for this. If there is a problem with this answer, please let me know (or try to [fix it yourself](http://stackoverflow.com/posts/23625331/edit) :P) – Tomas Aschan May 19 '14 at 06:47