How to render ggplot2 plots in html through Weave and RCall?

How do I include plots made with ggplot2 (through RCall) in html reports through Weave?

I try this (which works in a Jupyter notebook):

using RCall, DataFrames
d = DataFrame(x = [1,2,3], y = [4,5,6])
@rput d
@rlibrary ggplot2
ggplot(d, aes(x=:x,y=:y)) + geom_line()

and process it like this: using Weave; weave("test.jmd"; doctype = "md2html")

It gives this output:


I can work around it like this:

using RCall, DataFrames
d = DataFrame(x = [1,2,3], y = [4,5,6])
@rput d
p <- ggplot(d, aes(x=x,y=y)) + geom_line()

Then in the markdown put:


But that is not very satisfactory, as I need to manage filenames myself, and the plot is not embedded in the html output as native julia plots are.

Has anybody found a way around this?

Sorry, I’ve not run into this myself.

I was wondering what your motivation for using ggplot was… (it is an awesome library!). If it’s that you want a grammar-of-graphics-like approach to plotting in Julia: are you aware of AlgebraOfGraphics.jl or VegaLite.jl? They have similar design philosophies to ggplot and are being actively developed. e.g.

using AlgebraOfGraphics
d = DataFrame(x = [1,2,3], y = [4,5,6])
plt = data(d) * mapping(:x, :y) * visual(Lines)

Thanks for the suggestions @haberdashPI . I should probably look more into those options. Currently I’m trying to master Plots.jl.

My actual example is a bit more complex, but I’ll post it and ask for help with that as well :slight_smile:

I’ve posed the example here: How to make this plot in Julia?