In [2]:
source("https://raw.githubusercontent.com/eogasawara/mylibrary/master/myGraphics.R")

loadlibrary("MASS")
loadlibrary("gclus")
loadlibrary("RColorBrewer")
loadlibrary("gridExtra")
loadlibrary("GGally")
loadlibrary("reshape")
loadlibrary("dplyr")
loadlibrary("WVPlots")
loadlibrary("aplpack")

In [3]:
col.set <- brewer.pal(11, 'Spectral')
mycolors <- col.set[c(1,3,5,7,9)]

plot_size(4, 3)

In [4]:
data(iris)
t(sapply(iris, class))
iris[c(1:3,51:53,101:103),]


A matrix: 1 × 5 of type chr
Sepal.LengthSepal.WidthPetal.LengthPetal.WidthSpecies
numericnumericnumericnumericfactor
A data.frame: 9 × 5
Sepal.LengthSepal.WidthPetal.LengthPetal.WidthSpecies
<dbl><dbl><dbl><dbl><fct>
15.13.51.40.2setosa
24.93.01.40.2setosa
34.73.21.30.2setosa
517.03.24.71.4versicolor
526.43.24.51.5versicolor
536.93.14.91.5versicolor
1016.33.36.02.5virginica
1025.82.75.11.9virginica
1037.13.05.92.1virginica

In [5]:
sum <-summary(iris$Sepal.Length)
exp_table(t(sum), c("Statistics", "Freq") , proj=1)
IQR <- sum["3rd Qu."]-sum["1st Qu."]
print(sprintf("IQR=%.1f", IQR))


A data.frame: 6 × 2
StatisticsFreq
<fct><dbl>
Min. 4.300000
1st Qu.5.100000
Median 5.800000
Mean 5.843333
3rd Qu.6.400000
Max. 7.900000
[1] "IQR=1.3"

In [8]:
grfA <- plot.hist(iris %>% select(variable="Sepal.Length", value=Sepal.Length), label_x ="Sepal.Length", color=mycolors[1])
grfB <- plot.hist(iris %>% select(variable="Sepal.Width", value=Sepal.Width), label_x ="Sepal.Width", color=mycolors[1])
grfC <- plot.hist(iris %>% select(variable="Petal.Length", value=Petal.Length), label_x ="Petal.Length", color=mycolors[1])
grfD <- plot.hist(iris %>% select(variable="Petal.Width", value=Petal.Width), label_x ="Petal.Width", color=mycolors[1])

plot_size(7, 2)
grid.arrange(grfA, grfB, grfC, grfD, ncol=4, nrow=1)
plot_size(4, 3)



In [9]:
data <- melt(iris)
grfA <- plot.density(data, colors=mycolors[1:4])
plot(grfA)


Using Species as id variables

New section

Now, I am going to plot a density distribution with class label


In [10]:
grfA <- plot.density(iris %>% select(variable=Species, value=Sepal.Length), label_x = "Sepal.Length", color=mycolors[c(1:3)])
grfB <- plot.density(iris %>% select(variable=Species, value=Sepal.Width), label_x = "Sepal.Width", color=mycolors[c(1:3)])
grfC <- plot.density(iris %>% select(variable=Species, value=Petal.Length), label_x = "Petal.Length", color=mycolors[c(1:3)])
grfD <- plot.density(iris %>% select(variable=Species, value=Petal.Width), label_x = "Petal.Width", color=mycolors[c(1:3)])

plot_size(7, 4)
grid.arrange(grfA, grfB, grfC, grfD, ncol=2, nrow=2)
plot_size(4, 3)



In [11]:
data <- melt(iris)
grfA <- plot.boxplot(data, colors=mycolors[1:4])
plot(grfA)


Using Species as id variables

In [12]:
grfA <- plot.boxplot(iris %>% select(variable=Species, value=Sepal.Length), label_x = "Sepal.Length", color=mycolors[c(1:3)])
grfB <- plot.boxplot(iris %>% select(variable=Species, value=Sepal.Width), label_x = "Sepal.Width", color=mycolors[c(1:3)])
grfC <- plot.boxplot(iris %>% select(variable=Species, value=Petal.Length), label_x = "Petal.Length", color=mycolors[c(1:3)])
grfD <- plot.boxplot(iris %>% select(variable=Species, value=Petal.Width), label_x = "Petal.Width", color=mycolors[c(1:3)])

plot_size(7, 2)
grid.arrange(grfA, grfB, grfC, grfD, ncol=4, nrow=1)
plot_size(4, 3)



In [13]:
grfA <- exp_norm_dist(iris$Sepal.Length, label_y = "Sepal.Length", color=mycolors[1])
grfB <- exp_norm_dist(iris$Sepal.Width, label_y = "Sepal.Width", color=mycolors[1])
grfC <- exp_norm_dist(iris$Petal.Length, label_y = "Petal.Length", color=mycolors[1])
grfD <- exp_norm_dist(iris$Petal.Width, label_y = "Petal.Width", color=mycolors[1])

plot_size(7, 2)
grid.arrange(grfA, grfB, grfC, grfD, ncol=4, nrow=1)
plot_size(4, 3)



In [14]:
grf <- exp_correlation(iris[,1:4], color = mycolors[1:3]) 

plot(grf)



In [15]:
grf <- ggparcoord(data = iris, columns = c(1:4), group=5) + theme_bw(base_size = 10) + scale_color_manual(values=mycolors[1:3])

plot_size(5, 3)
plot(grf)
plot_size(4, 3)



In [17]:
grf <- exp_pair_plot(data=iris, cnames=colnames(iris)[1:4], title="Iris", colors=mycolors[1])

plot_size(7, 5)
grf
plot_size(4, 3)



In [18]:
grf <- exp_advpair_plot(data=iris, cnames=colnames(iris)[1:4], title="Iris", colors=mycolors[1])

plot_size(7, 5)
grf
plot_size(4, 3)



In [19]:
grf <- exp_advpair_plot(data=iris, cnames=colnames(iris)[1:4], title="Iris", clabel='Species', colors=mycolors[1:3])

plot_size(8, 5)
grf
plot_size(4, 3)


`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

In [20]:
mat <- as.matrix(iris[,1:4])
x <- (1:nrow(mat))
y <- (1:ncol(mat))
image(x, y, mat, col = col.set, axes = FALSE,  main = "Iris", xlab="sample", ylab="Attributes")
axis(2, at = seq(0, ncol(mat), by = 1))
axis(1, at = seq(0, nrow(mat), by = 10))



In [24]:
set.seed(1)
sample_rows = sample(1:nrow(iris), 25)

isample = iris[sample_rows,]
labels = as.character(rownames(isample))
isample$Species <- NULL


plot_size(8, 6)
faces(isample, labels = labels, print.info=F, cex=1)
plot_size(4, 3)



In [25]:
set.seed(1)
sample_rows = sample(1:nrow(iris), 25)

isample = iris[sample_rows,]
labels = as.character(isample$Species)
isample$Species <- NULL

plot_size(8, 6)
faces(isample, labels = labels, print.info=F, cex=1)
plot_size(4, 3)



In [ ]: