margin cheatsheet

#or
<img src="images/plot_margin.PNG"/>
reference: www.r-graph-gallery.com
http://vis.supstat.com/2013/04/plotting-symbols-and-color-palettes/
m <- matrix( c(4,6,4,6,4,6), nrow=2 )
# [,1] [,2] [,3]
# [1,] 4 4 4
# [2,] 6 6 6
barplot(m, legend=rownames(m), beside=TRUE)
# Sorting a boxplot based on median value
bymedian <- with(InsectSprays, reorder(spray, -count, median))
boxplot(count ~ bymedian, data = InsectSprays,
xlab = "spray", ylab = "count", varwidth=TRUE,
col = "lightgray")
library(ggplot2)
library(plyr)
#creates the values and data frame
time<- as.numeric(rep(seq(1,7),each=7))
value<- runif(49,30,100)
group<- rep(LETTERS[1:7], times=7)
data<-data.frame(time,value,group)
ggplot(data, aes(x=time, y=value, fill=group))+geom_area()
http://www.sthda.com/english/wiki/visualize-correlation-matrix-using-correlogram
plot with missing value: http://stackoverflow.com/questions/22000630/corrplot-machinedouble-eps-missing-value
https://rpubs.com/gaston/dendrograms
http://www.sigmath.es.osaka-u.ac.jp/shimo-lab/prog/pvclust/
hc <- hclust(dist(USArrests[1:7,]), "ave")
#--------- plot
suppressMessages(library(dendextend))
dend1 <- as.dendrogram(hc)
cutree(dend1,h=70) # it now works on a dendrogram with dendextend library
## Alabama Alaska Arizona Arkansas California Colorado
## 1 1 1 2 1 2
## Connecticut
## 3
#--------- plot
clus5 = cutree(hc, 5)
plot(hc, xlab = ""
, hang = -1 # set label height
)
rect.hclust(hc, h=70, border="blue")
rect.hclust(hc, h=30, border="red")
legend("topright", "(x,y)"
, c("Strong relation - red", "Good relation - blue") # add text
, text.col=c("red", "blue")
, lty=-1 , pch=NA # set lyt and pch to remove the legend symbols
)
x<- 1:10
y1 <- sample(seq(1:50), 10)
y2 <- sample(seq(100:200), 10)
# all sides have 2 lines of space margin to give space for axis on the right
par(oma=c(2,2,2,2))
# first plot
plot(x=x, y=y1, type="l", col="red")
# tell R to draw over the first plot
par(new=T)
# do second plot
plot(x=x, y=y2, type ="l", ylab="", yaxt='n' )
axis(4, (range(y2)), ylab='y2') # draw second axis on the right
mtext("y2", side=4, line=2.3, adj=0.5, cex=1) # add test label on the right
las: 0: always parallel to the axis [default], 1: always horizontal, 2: always perpendicular to the axis, 3: always vertical.
df <- iris[sample(nrow(iris), 30), ]
plot(df$Petal.Width, xaxt="n", xlab = "" )
axis(1, at=1:nrow(df), labels=df$Species, las=2, cex.axis=0.7)
y <- runif(10, 1, 5)
x <- seq_along(y)
y2 <- rep(y, each=2)[-(length(y)*2)]
x2 <- rep(x, each=2)[-1]
x3 <- c(min(x2), x2, max(x2))
y3 <- c(0, y2, 0)
plot(x, y, pch=16)
polygon(x3, y3, border=NA, col="grey60")
lines(x2, y2)
Producing Simple Graphs with R : http://www.harding.edu/fmccown/r/
http://personality-project.org/r/r.plottingdates.html
Hmisc http://rgm2.lab.nig.ac.jp/RGM2/func.php?rd_id=Hmisc:Ecdf
heatmap-or-plot-for-a-correlation-matrix http://stackoverflow.com/questions/15887212/heatmap-or-plot-for-a-correlation-matrix