multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) {
library(grid)
# Make a list from the ... arguments and plotlist
plots <- c(list(...), plotlist)
numPlots = length(plots)
# If layout is NULL, then use 'cols' to determine layout
if (is.null(layout)) {
# Make the panel
# ncol: Number of columns of plots
# nrow: Number of rows needed, calculated from # of cols
layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),
ncol = cols, nrow = ceiling(numPlots/cols))
}
if (numPlots==1) {
print(plots[[1]])
} else {
# Set up the page
grid.newpage()
pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout))))
# Make each plot, in the correct location
for (i in 1:numPlots) {
# Get the i,j matrix positions of the regions that contain this subplot
matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))
print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,
layout.pos.col = matchidx$col))
}
}
}
qqplot.data <- function (vec) # argument: vector of numbers
{
# following four lines from base R's qqline()
y <- quantile(vec[!is.na(vec)], c(0.25, 0.75))
x <- qnorm(c(0.25, 0.75))
slope <- diff(y)/diff(x)
int <- y[1L] - slope * x[1L]
d <- data.frame(resids = vec)
ggplot(d, aes(sample = resids)) + stat_qq(size=0.3) + geom_abline(slope = slope, intercept = int) + theme_bw() + xlab("Theoretical Quantiles") +ylab("Sample Quantiles")
}
plot.roc <- function(prediction,output.test) {
perf <- performance(prediction(prediction,output.test), measure="tpr", x.measure="fpr")
data.plot <- data.frame(x=perf@x.values[[1]],y=perf@y.values[[1]])
p <- ggplot(data=data.plot) + geom_line(aes(x=x,y=y)) + xlab("False Positive") + ylab("True Positive") + geom_abline(intercept=0,slope=1, linetype="dashed") + theme_bw()
p
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.