library(fdth)
#================================
# Vectors: univariated numerical
#================================
x <- rnorm(n=1e3,
mean=5,
sd=1)
(ft <- fdt(x))
# Histograms
plot(ft) # Absolute frequency histogram
plot(ft,
main='My title')
plot(ft,
x.round=3,
col='darkgreen')
plot(ft,
xlas=2)
plot(ft,
x.round=3,
xlas=2,
xlab=NULL)
plot(ft,
v=TRUE,
cex=.8,
x.round=3,
xlas=2,
xlab=NULL,
col=rainbow(11))
plot(ft,
type='fh') # Absolute frequency histogram
plot(ft,
type='rfh') # Relative frequency histogram
plot(ft,
type='rfph') # Relative frequency (%) histogram
plot(ft,
type='cdh') # Cumulative density histogram
plot(ft,
type='cfh') # Cumulative frequency histogram
plot(ft,
type='cfph') # Cumulative frequency (%) histogram
# Poligons
plot(ft,
type='fp') # Absolute frequency polygon
plot(ft,
type='rfp') # Relative frequency polygon
plot(ft,
type='rfpp') # Relative frequency (%) polygon
plot(ft,
type='cdp') # Cumulative density polygon
plot(ft,
type='cfp') # Cumulative frequency polygon
plot(ft,
type='cfpp') # Cumulative frequency (%) polygon
# Density
plot(ft,
type='d') # Density
# Theoretical curve and fdt
x <- rnorm(1e5,
mean=5,
sd=1)
plot(fdt(x,
k=100),
type='d',
col=heat.colors(100))
curve(dnorm(x,
mean=5,
sd=1),
col='darkgreen',
add=TRUE,
lwd=2)
#==================================
# Vectors: univariated categorical
#==================================
x <- sample(letters[1:5],
1e3,
rep=TRUE)
(ft.c <- fdt_cat(x))
# Barplot: the default
plot(ft.c)
# Barplot
plot(ft.c,
type='fb')
# Polygon
plot(ft.c,
type='fp')
# Dotchart
plot(ft.c,
type='fd')
# Pareto chart
plot(ft.c,
type='pa')
#=============================================
# Data.frames: multivariated with categorical
#=============================================
mdf <- data.frame(X1=rep(LETTERS[1:4], 25),
X2=as.factor(rep(1:10, 10)),
Y1=c(NA, NA, rnorm(96, 10, 1), NA, NA),
Y2=rnorm(100, 60, 4),
Y3=rnorm(100, 50, 4),
Y4=rnorm(100, 40, 4),
stringsAsFactors=TRUE)
# Histograms
(ft <- fdt(mdf,
na.rm=TRUE))
plot(ft,
v=TRUE,
cex=.8)
plot(ft,
col='darkgreen',
ylim=c(0, 40))
plot(ft,
col=rainbow(8),
ylim=c(0, 40),
main=LETTERS[1:4])
plot(ft,
type='fh')
plot(ft,
type='rfh')
plot(ft,
type='rfph')
plot(ft,
type='cdh')
plot(ft,
type='cfh')
plot(ft,
type='cfph')
# Poligons
plot(ft,
v=TRUE,
type='fp')
plot(ft,
type='rfp')
plot(ft,
type='rfpp')
plot(ft,
type='cdp')
plot(ft,
type='cfp')
plot(ft,
type='cfpp')
# Density
plot(ft,
type='d')
levels(mdf$X1)
plot(fdt(mdf,
k=5,
by='X1',
na.rm=TRUE),
ylim=c(0, 12))
levels(mdf$X2)
plot(fdt(mdf,
breaks='FD',
by='X2',
na.rm=TRUE))
plot(fdt(mdf,
k=5,
by='X2',
na.rm=TRUE)) # It is difficult to compare
plot(fdt(mdf,
k=5,
by='X2',
na.rm=TRUE),
ylim=c(0, 8)) # Easy
plot(fdt(iris,
k=5))
plot(fdt(iris,
k=5),
col=rainbow(5))
plot(fdt(iris,
k=5,
by='Species'),
v=TRUE)
ft <- fdt(iris,
k=10)
plot(ft)
plot(ft,
type='d')
# Categorical data
(ft.c <- fdt_cat(mdf))
plot(ft.c)
plot(ft.c,
type='fd',
pch=19)
#=========================
# Matrices: multivariated
#=========================
plot(fdt(state.x77))
plot(fdt(volcano))
Run the code above in your browser using DataLab