How to plot lattice and ggplot2 graphs with FastRWeb

April 10, 2012

(This article was first published on Rronan » R, and kindly contributed to R-bloggers)

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("<!doctype html><html><head><title>Plots</title>", "<meta charset='UTF-8'/></head><body><h1>Some plots…</h1>", sep = "") X <- rnorm(100) Y <- rnorm(100) out("<h2>graphics</h2>") p <- WebPlot(580, 580) plot(x = X, y = Y, pch = 19) out(p) out("<h2>ggplot2</h2>") require(ggplot2) p <- WebPlot(580, 580) print(qplot(x = X, y = Y, pch = 19)) out(p) out("<h2>lattice</h2>") require(lattice) p <- WebPlot(580, 580) print(xyplot(x = Y ~ X, pch = 19)) out(p) out("</body></html>") done() }

With this script, you should see three graphics.








Licence Creative Commons

To leave a comment for the author, please follow the link and comment on their blog: Rronan » R. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

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

Tags: , , , , , , , ,

Comments are closed.


Mango solutions

RStudio homepage

Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training


CRC R books series

Contact us if you wish to help support R-bloggers, and place your banner here.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)