# How to plot lattice and ggplot2 graphs with FastRWeb

April 10, 2012
By

[This article was first published on 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("")
done()
}
```

With this script, you should see three graphics.

#### lattice

##### References

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.

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , , , , , , ,