plot

Two-colored symbols

No votes yet

The R plotting symbols pch=21:25 have borders and backgrounds. col gives the border color and bg the background color. (R version 2.8.x)

Example:

opar<-par(mar=c(0,0,2,0),oma=c(0,0,0,0))
plot(1:5,rep(1,5),col='blue',bg='red',pch=21:25,cex=4,
   lwd=2,axes=FALSE,xlim=c(0,6),ylim=c(0.5,1.5),
   main="two-colored symbols",xlab="")
text(1:5,rep(1,5),labels="21":"25")
par(opar)

Simple k-means cluster analysis and plot

Average: 4 (1 vote)

We know that the iris data set include three species. K-means does a pretty good job of correctly identifying correct groups.

data(iris)
cl <- kmeans(iris[,1:4], 3)
cl$cluster
cbind(1:150,iris$Species)

cl$cluster reveals which group each observation was placed in; compare this with a listing of the species designations mapped next to 150 index values (cbind(1:150,iris$Species)).

Read more

Syndicate content