Visualization and Statistics

TypeR codePlot
lineplot(c~b, type = "l") Paper clips
box plotboxplot(a,b,c,col=cm.colors(8)) Paper clips
scatter plotplot(a~b) Paper clips
pairwise scatter plotpairs(x) Paper clips
trend line with error enveloplibrary(ggplot2);
CC <- read.table("http://www.sr.bham.ac.uk/~ajrs/papers/sanderson06/mean_Tprofile-CC.txt", header=TRUE)
nCC <- read.table("http://www.sr.bham.ac.uk/~ajrs/papers/sanderson06/mean_Tprofile-nCC.txt", header=TRUE)
CC$type <- "Cool core";
nCC$type <- "Non-cool core";
A <- rbind(CC, nCC)
ggplot(data=A, aes(x=r.r500, y=sckT, ymin=sckT.lo, ymax=sckT.up, fill=type, linetype=type)) +
geom_line() + geom_ribbon(alpha=0.5) + scale_x_log10() + scale_y_log10()

ref http://www.r-graph-gallery.com/104-plot-lines-with-error-envelopes-ggplot2/
Paper clips
violin plotlibrary(vioplot);
with(data , vioplot( value[treatment=="A"] , value[treatment=="B"], col=rgb(0.1,0.4,0.7,0.7) , names=c("A","B") ))
Page clips
bubble plotsymbols(aa[,1], aa[,6], circles=aa[,10]/5, inches=0.10, fg="white", bg=" darkorchid4") Page clips
two y axespar(mar=c(5,4,4,5)+.1)
plot(x,y1,type="l",col="red")
par(new=TRUE)
plot(x, y2,,type="l",col="blue",xaxt="n",yaxt="n",xlab="",ylab="")
axis(4)
mtext("y2",side=4,line=3)
legend("topleft",col=c("red","blue"),lty=1,legend=c("y1","y2"))
Page clips
circular tree plotlibrary(dendextend)
library(circlize)
hc <- hclust(dist(datasets::mtcars))
dend <- as.dendrogram(hc)
par(mar = rep(0,4))
circlize_dendrogram(dend, labels_track_height = NA, dend_track_height = .4)
Page clips
heatmaplibrary(gplots);library(RColorBrewer);
hc <- hclust(dist(datasets::mtcars))
heatmap.2(datasets::mtcars,hclustfun = function(x)hclust(x,method = "average"), dendrogram = 'both')
Page clips
densitylibrary(rattle); library(ggplot2)
cities <- c("Canberra", "Melbourne", "Sydney")
ds <- subset(weatherAUS, Location cities & ! is.na(MaxTemp))
p <- ggplot(ds, aes(MaxTemp, colour=Location, fill=Location))
p <- p + geom_density(alpha=0.55)
p

ref http://www.r-graph-gallery.com/21-distribution-plot-using-ggplot2/
Page clips
centipedeset.seed(9001)
p.value <- vector()
dataf <- as.data.frame(matrix(rep(NA, 2000), nrow=100))
names(dataf) <- c(paste("V",1:19, sep=""), "y")
for(i in 1:20)
{ dataf[,i] <- rnorm(20, 50, 10) }
require (plotrix)
seg<-get.segs(dataf) [[<<]centipede.plot(seg, main= "A centipede plot",vgrid=c(10))
grid(nx = 10, ny = 19, col = "gray50")

ref http://rgraphgallery.blogspot.com/search/label/centepede%20plot
Page clips
pairwise comparisonlibrary(multcompView)
model=lm( data$value ~ data$treatment )
ANOVA=aov(model)
TUKEY <- TukeyHSD(x=ANOVA, 'data$treatment', conf.level=0.95)
plot(TUKEY , las=1 , col="brown" )

ref http://www.r-graph-gallery.com/84-tukey-test/
Page clips
butterfly plotsource("/panfs/pan1.be-md.ncbi.nlm.nih.gov/devdcode/di/resource/buttfly.R")
p1 = butterfly(100, 1000, title="100 x 1000")

ref http://www.r-bloggers.com/the-butterfly-curve-2/
Page clips
3-D surface (matlab)[X,Y] = meshgrid(-2:.2:2);
Z = X .* exp(-X.^2 - Y.^2);
surf(X,Y,Z)
Page clips
polar axisggplot(aa,aes(x = legend.var, y = score, fill = Indicator))+
geom_bar(width=1,alpha= 0.5,stat="identity") +
scale_y_continuous() +
coord_polar() +
theme(axis.ticks = element_blank())
Page clips
multiple panelsp1 <- ggplot(DF,aes(y=motif,x=y,colour=factor(group))) + geom_point()
p2 <- ggplot(DF,aes(x=y,colour=factor(group),fill=factor(group))) +
scale_y_continuous() +
coord_polar() + geom_density(alpha=0.5)
p3 <- ggplot(DF,aes(x=motif,colour=factor(group),fill=factor(group))) + geom_density(alpha=0.5) + coord_flip()
grid.arrange(arrangeGrob(p2,ncol=2,widths=c(3,1)),
arrangeGrob(p1,p3,ncol=2,widths=c(3,1)),
heights=c(1,3))
Page clips
boxplot with data pointsdf <- ToothGrowth
df$dose <- as.factor(df$dose)
p <- ggplot(df, aes(x=dose, y=len)) +
geom_dotplot(binaxis='y', stackdir='center') +
stat_summary(fun.data="mean_sdl", mult=1, geom="crossbar", width=0.5)
Page clips
scatterplot with error barggplot(data = df,aes(x = x,y = y)) +
geom_point() +
geom_errorbar(aes(ymin = ymin,ymax = ymax)) +
geom_errorbarh(aes(xmin = xmin,xmax = xmax))

ref http://stackoverflow.com/questions/9231702/ggplot2-adding-two-errorbars-to-each-point-in-scatterplot
Page clips
diverging stacked barrequire(likert)
data(pisaitems)data(pisaitems)
items24 <- pisaitems[,substr(names(pisaitems), 1,5) == 'ST24Q'] [<<]]l24 <- likert(items24) [<<]]plot(l24)

ref https://github.com/jbryer/likert/blob/master/demo/likert.R
Page clips
scatterplot error bar polar coordinatorggplot(data = df,aes(x = x,y = y)) +
geom_point() +
geom_errorbar(aes(ymin = ymin,ymax = ymax)) +
coord_polar()
Page clips
stack bar polar coordinatorggplot(mdfr, aes(category, value, fill = variable)) +
geom_bar(position="fill",width=0.8,alpha= 0.5,stat="identity") +
coord_polar() +
theme(axis.ticks = element_blank())
Page clips
two y axes IIdf <- data.frame(stolpec1 = 10 * runif(10), stolpec2 = 100+10 * runif(10))
barplot(df$stolpec1,ylim=c(0,30))
par(new=TRUE)
plot(1:10, df$stolpec2,,type="l",col="blue",xaxt="n",yaxt="n",xlab="",ylab="",ylim=c(80,120))
axis(4)
mtext("y2",side=4,line=3)
legend("topleft",col=c("grey","blue"),lty=1,legend=c("y1","y2"))
Page clips
3D scatter plotlibrary("plot3D")
scatter3D_fancy(x, y, z, pch = 16,
ticktype = "detailed", theta = 15, d = 2, [<<]]main = "Iris data", clab = c("Petal", "Width (cm)") )

ref http://www.sthda.com/english/wiki/impressive-package-for-3d-and-4d-graph-r-software-and-data-visualization
Page clips
3D scatter plot II(MATLAB) stem3(z,x,y,'.','marksize',30)
grid on;
box on
Page clips
3D surface with project lines(MATLAB) surfc(X,Y,Z)
grid on;
box on
Page clips