티스토리 뷰
frequency polygons
As i surfed around the web, I came across this lecture
Statistics 202: Statistical Aspects of Data Mining, Summer 2007
It drew my attention and I watched the first video and the whole slides from the web. It wasn't so hard.
Anyway, the Lecturer introduces frequnecy polygon, which looks cool. So I implemented it as a function, freqPolygon.
Here's the code.
freqPolygon = function(data, new = T, lty = "solid", col, border = col, ...) {
histDflt <- hist(data, plot = F, ...)
counts <- histDflt$counts
breaks <- histDflt$breaks
breaksInterval <- breaks[2] - breaks[1]
breaksNew <- c(breaks[1], breaks[-(length(breaks))] + breaksInterval/2,
breaks[length(breaks)])
countsNew <- c(0, counts, 0)
if (new == T) {
plot(breaksNew, countsNew, col = col, pch = 19, ...)
} else {
points(breaksNew, countsNew, col = col, pch = 19, ...)
}
polygon(breaksNew, countsNew, col = col, lty = lty, border = border, ...)
result = list()
result$breaks = breaksNew
result$counts = countsNew
invisible(result)
}
And Here are some examples
freqPolygon(c(2, 3, 4, 2, 5, 2, 3), col = "blue", new = T)
freqPolygon(c(1, 2, 1, 1, 2, 3, 2), col = "red", new = F, lty = "dotted")
freqPolygon(c(2, 3, 4, 2, 5, 2, 3), col = "blue", new = T)
freqPolygon(c(1, 2, 1, 1, 2, 3, 2), col = "red", new = F, lty = "dotted")
freqPolygon(c(2, 3, 4, 2, 5, 2, 3), col = rgb(0, 0, 1, 0.2), new = T)
freqPolygon(c(1, 2, 1, 1, 2, 3, 2), col = rgb(1, 0, 0, 0.2), new = F, lty = "dotted")
freqPolygon(c(2, 3, 4, 2, 5, 2, 3), col = rgb(0, 0, 1, 0.2), new = T, xlim = c(0,
6))
## Warning: argument 'xlim' is not made use of
freqPolygon(c(1, 2, 1, 1, 2, 3, 2), col = rgb(1, 0, 0, 0.2), new = F, lty = "dotted",
xlim = c(0, 6))
## Warning: argument 'xlim' is not made use of
freqPolygon(c(2, 3, 4, 2, 5, 2, 3), col = rgb(0, 0, 1, 0.2), new = T, xlim = c(0,
6), ylim = c(0, 6), freq = F)
## Warning: arguments 'freq', 'xlim', 'ylim' are not made use of
## Warning: "freq" is not a graphical parameter
## Warning: "freq" is not a graphical parameter
## Warning: "freq" is not a graphical parameter
## Warning: "freq" is not a graphical parameter
## Warning: "freq" is not a graphical parameter
## Warning: "freq" is not a graphical parameter
## Warning: "freq" is not a graphical parameter
freqPolygon(c(1, 2, 1, 1, 2, 3, 2), col = rgb(1, 0, 0, 0.2), new = F, lty = "dotted",
xlim = c(0, 6), ylim = c(0, 6), freq = F)
## Warning: arguments 'freq', 'xlim', 'ylim' are not made use of
## Warning: "freq" is not a graphical parameter
## Warning: "freq" is not a graphical parameter
You see some warnings. Just ignore it.
Function col2rgb tells you how to figure argument to superimpose two frequency polygons.
col2rgb("red")
## [,1]
## red 255
## green 0
## blue 0
col2rgb("blue")
## [,1]
## red 0
## green 0
## blue 255
'차기작 : R을 배우자' 카테고리의 다른 글
R source for lempel-ziv complexity (0) | 2014.08.02 |
---|---|
R studio, Git, BitBucket (0) | 2014.02.25 |
R and Python : 번역 (0) | 2014.02.15 |
Python and R (0) | 2014.02.15 |
and R (0) | 2014.02.15 |