# How to plot lattice and ggplot2 graphs with FastRWeb

[This article was first published on

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

**Rronan » R**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

#### With `print()`

If you are an advanced R user, you probably know the lattice and the ggplot2 packages. They allow you to plot elegant graphics with less code (Hocking, 2009 and Sueur, 2010). If you know these two packages, you should hardly use `plot()`

for your graphs.

If you read my article on FastRWeb, you may have wanted to try it with ggplot2 or lattice graphs. Your graphics have perhaps not been plotted. You did a Google search and you just learned you need the `plot()`

function to properly display ggplot2 or lattice graphs with FastRWeb.

The code below shows how to reproduce the graph of `/var/FastRWeb/web.R/example1.png.R`

with lattice and ggplot2.

run <- function(...) { out("Plots ", "## Some plots…

", sep = "") X <- rnorm(100) Y <- rnorm(100) out("## graphics

") p <- WebPlot(580, 580) plot(x = X, y = Y, pch = 19) out(p) out("## ggplot2

") require(ggplot2) p <- WebPlot(580, 580) print(qplot(x = X, y = Y, pch = 19)) out(p) out("## lattice

") require(lattice) p <- WebPlot(580, 580) print(xyplot(x = Y ~ X, pch = 19)) out(p) out("%MINIFYHTMLd19ce83c4bca187501f1a88c31f326638%") done() }

With this script, you should see three graphics.

#### graphics

#### ggplot2

#### lattice

##### References

- Hocking T.
*Le package lattice pour visualiser les données multivariées*. Semin-R du MNHN, 15 Octobre 2009. - Sueur J.
*Une nouvelle génération de graphiques : introduction à ggplot2*. Semin-R du MNHN, 20 Mai 2010.

To

**leave a comment**for the author, please follow the link and comment on their blog:**Rronan » R**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.