Zhiguang Huo (Caleb)
Wednesday September 12, 2018
R is powerful to visualize your data.
## [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
pdf("sinFunction.pdf")
n <- 80
set.seed(32611)
x <- sort(runif(n, min = 0, max=2*pi))
y <- sin(x) + rnorm(n, mean = 0, sd = 0.2)
plot(x,y)
dev.off()
## quartz_off_screen
## 2
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1 5.1 3.5 1.4 0.2 setosa
## 2 4.9 3.0 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
## 4 4.6 3.1 1.5 0.2 setosa
## 5 5.0 3.6 1.4 0.2 setosa
## 6 5.4 3.9 1.7 0.4 setosa
## 'data.frame': 150 obs. of 5 variables:
## $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
## $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
## $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
## $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
## $ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
## [1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width"
## [5] "Species"
par(mfrow = c(2,2))
xlims <- range(iris$Petal.Length) ## set common x limits
uniqueSpecies <- levels(iris$Species)
for(i in 1:3){
aspecies <- uniqueSpecies[i]
sampleSelection <- iris$Species==aspecies
adata <- iris$Petal.Length[sampleSelection]
hist(adata, col=i, xlim=xlims, xlab="petal length",main=aspecies)
}
B=16
greenRed <- rgb(c(rep(0, B), (0:B)/B), c((B:0)/16, rep(0, B)), rep(0, 2*B+1))
species <- iris$Species
levels(species) <- 1:3
rowColor <- palette()[species]
heatmap(matrix, col= greenRed, margin=c(7,7),
Rowv = NA, Colv = NA, RowSideColors = rowColor)
legend("topright",legend = levels(iris$Species),fill=levels(species))
B=16
greenRed <- rgb(c(rep(0, B), (0:B)/B), c((B:0)/16, rep(0, B)), rep(0, 2*B+1))
species <- iris$Species
levels(species) <- 1:3
rowColor <- palette()[species]
heatmap(matrix, col= greenRed, margin=c(7,7),
Rowv = NA, Colv = NA,
RowSideColors = rowColor,
labRow = "", labCol = "", main="heatmap of iris data")
legend("topright",legend = levels(iris$Species),fill=levels(species))