################# htmlMaker sample pages #########################################
# These are set up to work under R in interactive mode, change
# plot.method="png"
# below to work for other situations. The comments at the top of function
# htmlPlotBegin in htmlMaker.R explain the choices.
path <- "/temp/"
cat("htmlMakerTest is assuming you are running R in interactive mode\n",
"See comments to make the changes to run R in batch or S-Plus.\n",
"Output files are in directory ",path,"\n",sep="")
# data for x-y plot
x<-seq(1,12)
y<-runif(12)
# data for barplot
ht <- runif(8)
ht[3] <- 0 # test with a bar of zero height
# data for boxplot
x1 <- rnorm(50)
x2 <- rnorm(200,mean=3,sd=sqrt(.2))
x3 <- rep(-1,20) # test with a degenerate data set(no spread)
x4 <- rgamma(100,shape=.3)
##########################################################
# simple page, graphs not active
cat("Starting page1\n")
pg <- htmlPageBegin(path,"page1.html",title="Page 1",plot.method="png",
comment="test of plot functions")
htmlLine( pg, "
Simple plots, no options or active regions
" )
htmlPlot(pg, x, y, plot.file="plot1.png",main="x-y plot" )
htmlBarPlot(pg, ht, plot.file="barplot1.png",main="Barplot" )
htmlBoxPlot( pg, list(x1,x2,x3,x4), "boxplot1.png",main="Boxplot" )
# a table with links to other pages
htmlLine( pg, "
" )
htmlTableBegin( pg, caption="
Other pages" )
htmlTableRow( pg, c("simple plots",
"clickable plots",
"color plots, tables",
"3-D plots, multiple panels, etc." ) )
htmlTableEnd( pg)
htmlLine( pg, "" )
htmlPageEnd( pg )
##########################################################
# active plots
cat("Starting page2\n")
pg <- htmlPageBegin(path,"page2.html",title="Page 2",plot.method="png",
comment="\ntest of plot functions")
htmlLine( pg, "Simple plots, using a few options and active regions
" )
links <- rep( "clicked.html", length(x))
htmlPlot(pg, x,y, plot.file="plot2.png", hyperlink=links,
main="clickable x-y plot - click on a point")
group.names <- paste("grp",1:length(ht),sep="")
htmlBarPlot(pg, ht, plot.file="barplot2.png",main="Clickable barplot",hyperlink=links[1:length(ht)],
group.names=group.names )
htmlBoxPlot( pg, list(x1,x2,x3,x4), "boxplot2.png",main="Clickable boxplot",
hyperlink=links, group.names=c("N(0,1)","N(3,0.2)","const","Gamma(0.3)") )
# a table with links to other pages
htmlLine( pg, "
" )
htmlTableBegin( pg, caption="
Other pages" )
htmlTableRow( pg, c("simple plots",
"clickable plots",
"color plots, tables",
"3-D plots, multiple panels, etc." ) )
htmlTableEnd( pg)
htmlLine( pg, "" )
htmlPageEnd( pg )
##########################################################
# a simple page to verify user clicking on a point
cat("Starting clicked\n")
pg <- htmlPageBegin(path,"clicked.html","You clicked",plot.method="png",
comment="\ntest of plot functions")
htmlLine( pg, "You clicked on an active region...
")
htmlLine( pg, 'Use the "back" button on your browser or select one of the pages below
')
# a table with links to other pages
htmlLine( pg, "
" )
htmlTableBegin( pg, caption="
Other pages" )
htmlTableRow( pg, c("simple plots",
"clickable plots",
"color plots, tables",
"3-D plots, multiple panels, etc." ) )
htmlTableEnd( pg)
htmlLine( pg, "" )
htmlPageEnd(pg)
##########################################################
# a more complicated page
cat("Starting page3\n")
pg <- htmlPageBegin(path,"page3.html",title="Page 3",body.options="BGCOLOR=99CCFF",
plot.method="png",comment="\ntest of plot functions")
htmlLine( pg, "More examples using options like color, size, etc.
" )
htmlLine( pg, "Here are the same random points with bigger viewing window and showing lines
" )
htmlPlot(pg, x, y, links, plot.file="plot3.png", xlim=c(0,6),ylim=c(-2,2),type="b" )
htmlLine( pg, "Here are the same random points with smaller window, only lines and centered
" )
htmlLine( pg, "
" )
htmlPlot( pg, x, y, links, plot.file="plot4.png", plot.size=c(500,250), type="l" )
htmlLine( pg, "
" )
htmlBarPlot(pg, ht, plot.file="barplot3.png",main="Colored barplot",color=1:8 )
x <- rnorm(10)
y <- rnorm(10)
links <- rep( "page2.html", length(x))
htmlLine( pg,"Here is a wide plot with title and more points with smaller active regions
" )
htmlPlot(pg, x, y, links, plot.file="plot5.png",
plot.size=c(1000,200),active.region.size=1,xlab="",ylab="",main="rnorm vs rnorm" )
# example of table
htmlLine( pg, "
" )
htmlTableBegin( pg, caption="Here is a simple table" )
htmlTableRow( pg, c("Name","Phone","E-mail"), header=T )
htmlTableRow( pg, c("John","x1234","john@nowhere.com"))
htmlTableRow( pg, c("Martha","x5678","martha@nowhere.com"))
htmlTableRow( pg, c("Julia","x4321","julia@nowhere.com"))
htmlTableRow( pg, c("Erin","x8765","erin@nowhere.com"))
htmlTableEnd( pg)
htmlLine( pg, "
" )
# table write
x <- matrix(100*runif(15),3,5)
htmlWriteMatrix( pg, x, 3, caption="matrix x with row and column labels" )
htmlWriteMatrix( pg, x, 3, caption="x with no labels",row.labels=F,col.labels=F )
y <- rcauchy(10)
htmlWriteMatrix( pg, y, 3, caption="Here is a vector y")
htmlLine( pg, "
" )
x <- 1:10
y <- rnorm(10)
links <- rep( "#showdata", length(x))
htmlPlot( pg, x,y, plot.filename="generic2.png",hyperlink=links,
main="Click on a point to see table of data values",
xlab="time", ylab="response", col="#FF0000",type="b" )
htmlLine( pg, "" )
htmlLine( pg, "
" )
htmlWriteMatrix( pg, cbind(x,y), digits=3, row.labels=F,col.labels=FALSE )
htmlLine( pg, "
" )
htmlLine( pg, "Here are some standard html features: a list" )
htmlLine( pg, " " )
htmlLine( pg, " - Netscape" )
htmlLine( pg, "
- Internet Explorer" )
htmlLine( pg, "
- Mosaic" )
htmlLine( pg, "
" )
htmlLine( pg, "
" )
# fancy table
htmlTableBegin( pg, caption="
Fancy table of fake astronomical objects
" )
color1 = "BGCOLOR=#FFFFFF"
color2 = "BGCOLOR=#FFFFCC"
htmlTableRow(pg, c("Object","location","mass" ), header.row=TRUE,
tr.options=color2, td.options=c("ROWSPAN=2","COLSPAN=3","ROWSPAN=2") )
htmlTableRow(pg, c("x","y","z" ), header.row=TRUE, tr.options=color2 )
count <- 0
for (i in 1:10) {
count <- count + 1
row <- c(paste("asteriod",i),round(runif(4),digits=3))
if (count == 3) {
count <- 0
htmlTableRow(pg, row, tr.options=color2 )
} else htmlTableRow(pg, row, tr.options=color1 )
}
htmlTableEnd( pg )
htmlLine( pg, "
" )
# a table with links to other pages
htmlTableBegin( pg, caption="Other pages" )
htmlTableRow( pg, c("simple plots",
"clickable plots",
"color plots, tables",
"3-D plots, multiple panels, etc." ) )
htmlTableEnd( pg)
htmlLine( pg, "" )
htmlPageEnd(pg)
########################################################################
# these examples show how to include any R plot on a web page
# such plots are NOT clickable
cat("Starting page4\n")
pg <- htmlPageBegin(path,"page4.html",title="Page 4",body.options="BGCOLOR=#FFFFCC",
plot.method="png",comment="\ntest of plot functions")
htmlLine(pg, " Include any graph in a webpage - these graphs are not clickable
")
# a 3-D perspective plot
htmlLine( pg, "
" )
htmlPlotBegin( pg, "generic3.png",plot.size=c(500,500) ) # use square box
x <- seq(-2,2,length=41)
y <- x
plot.func <- function(x,y) { r <- sqrt(x^2+y^2)
cos(5*r)*exp(-.7*r) }
z <- outer(x,y,plot.func)
persp(x,y,z,phi=60,theta=30,col="blue",main="3-D perspective plot")
htmlPlotEnd(pg, "generic4.png" )
# a panel of 4 plots
htmlLine( pg, "
Multiple plots on a single image
")
htmlLine( pg, "
" )
htmlPlotBegin( pg, "generic5.png" )
par(mfrow=c(2,2))
plot(x1,main='x1')
plot(x2,type='l',main='x2')
plot(x3,type='b',main='x3')
plot(x4,type='l',main='x4')
htmlPlotEnd( pg, "generic5.png" )
# trellis type plot
htmlLine( pg, "
coplot from R help(coplot)
")
htmlLine( pg, "
" )
htmlPlotBegin( pg, "generic6.png" )
data(warpbreaks)
coplot(breaks ~ 1:54 | wool * tension, data = warpbreaks,
col = "red", bg = "pink", pch = 21,
bar.bg = c(fac = "light blue"))
htmlPlotEnd( pg, "generic6.png" )
# image/contour plot
htmlLine( pg, "
Persian rug image/contour plot from R help(contour)
")
htmlLine( pg, "
" )
htmlPlotBegin( pg, "generic7.png",plot.size=c(600,600) )
x <- y <- seq(-4*pi, 4*pi, len=27)
r <- sqrt(outer(x^2, y^2, "+"))
z <- cos(r^2)*exp(-r/6)
image(z, axes = FALSE, main = "Math can be beautiful ...",
xlab = expression(cos(r^2) * e^{-r/6} ))
contour(z, add = TRUE, drawlabels = FALSE)
htmlPlotEnd( pg, "generic7.png" )
# a table with links to other pages
htmlLine( pg, "
" )
htmlTableBegin( pg, caption="
Other pages