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

**URL:** https://discourse.julialang.org/t/how-to-render-ggplot2-plots-in-html-through-weave-and-rcall/74913
**Category:** General Usage
**Tags:** weave, rcall
**Created:** [January 20, 2022, 8:29am UTC](https://discourse.julialang.org/t/how-to-render-ggplot2-plots-in-html-through-weave-and-rcall/74913 "2022-01-20T08:29:17Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tp2750](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tp2750/32/207806_2.png) [@tp2750](https://discourse.julialang.org/u/tp2750)
#### Post date: [January 20, 2022, 8:29am UTC](https://discourse.julialang.org/t/how-to-render-ggplot2-plots-in-html-through-weave-and-rcall/74913/1 "2022-01-20T08:29:17Z")

</div>

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

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

```julia
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:

![billede](https://global.discourse-cdn.com/julialang/original/3X/4/8/48a3393f8319f1fd7add139979492ce089e2c428.png)

I can work around it like this:

```julia
using RCall, DataFrames
d = DataFrame(x = [1,2,3], y = [4,5,6])
@rput d
R"""
library(ggplot2)
p <- ggplot(d, aes(x=x,y=y)) + geom_line()
png("plot01.png")
print(p)
dev.off()
"""

```

Then in the markdown put:

```julia
![plot01](plot01.png)

```

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?

---

<div class="post-metadata">

### Author: ![haberdashPI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/haberdashpi/32/26337_2.png) [@haberdashPI](https://discourse.julialang.org/u/haberdashPI)
#### Post date: [January 22, 2022, 1:52pm UTC](https://discourse.julialang.org/t/how-to-render-ggplot2-plots-in-html-through-weave-and-rcall/74913/2 "2022-01-22T13:52:50Z")

</div>

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](http://juliaplots.org/AlgebraOfGraphics.jl/stable/) or [VegaLite.jl](https://www.queryverse.org/VegaLite.jl/stable/)? They have similar design philosophies to ggplot and are being actively developed. e.g.

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

```

---

<div class="post-metadata">

### Author: ![tp2750](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tp2750/32/207806_2.png) [@tp2750](https://discourse.julialang.org/u/tp2750)
#### Post date: [January 23, 2022, 1:14pm UTC](https://discourse.julialang.org/t/how-to-render-ggplot2-plots-in-html-through-weave-and-rcall/74913/3 "2022-01-23T13:14:45Z")

</div>

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 🙂

I’ve posed the example here: [How to make this plot in Julia?](https://discourse.julialang.org/t/how-to-make-this-plot-in-julia/75065)
