[R] Panel.abline would not show beyond a certain slope value
Uwe Ligges
ligges at statistik.tu-dortmund.de
Mon Apr 9 16:56:37 CEST 2012
On 09.04.2012 06:31, Aziz, Muhammad Fayez wrote:
>
> Hi,
>
> Please find the code and data following. Problem appears in lines 37 - 42 of the code. I am using R.2.13.0 on WinXP.
Works for me with a recent version of R (i.e. 2.15.0) / grid and lattice
(i.e. 0.20-6).
Please always try with recent versions of R and packages before asking.
Best,
Uwe Ligges
> Regards,
> Fayez
>
>
> PowerLawGraphsAblineQn.Râ
>
> library('reshape')
> library(lattice)
> library(igraph) # to use power.law.fit function
> library(latticeExtra) # to use panel.lmlineq in loglog xyplot
>
> File2Open = "C:\\Documents and Settings\\All Users\\Documents\\Desktop\\Fayez\\RPractice\\PowerLawGraphsAblineQnData.txt"
> DataTable = read.table(File2Open, header = TRUE, sep = "\t")
> md<- melt(DataTable, id.vars = c('Range', 'TheValue', 'TheNo')) # removed 'DegType' column 030312
> md$variable<- as.numeric(substr(md$variable, 9, nchar(as.character(md$variable))))
>
>
> mypanel4loglog<-
> function(x, # x is the variable column in melted data, equals the Domain Nos
> y, # y is the value column in melted data, the degrees
> ... # Rest of the arguments
> )
> {
>
> kfreq<- table(y); # compute frquency hash table of y, the values
> k<- 1:max(y)
> for (i in k) {
> ichar<- as.character(i) # convert to match the names(freq), the character-based hash key of freq, which is the value
> if (!(ichar %in% names(kfreq)))
> kfreq[ichar]<- 0
> }
> sortedkeys<- as.character(k)
> kfreq<- kfreq[sortedkeys]
> pk<- kfreq / length(y)
> logk<- log(k)
> logpk<- log(pk)
>
> logpk[logpk == -Inf] = "" # remove the -Inf or log(p(k)) = 0 values for lm function, NULL is 0-length so use "" instead that has length of one null character
> logpk<- as.numeric(logpk) # "" converts all values to character, lm needs numeric
> print(rbind(logk, logpk))# write.table(rbind(k, kfreq, pk, logk, logpk), paste(FilePath, "\\data", sep=""), sep = "\t", append = TRUE)
>
> panel.xyplot(col="blue", logk, logpk, type = c('p', 'r'))
>
> lm.r = lm(logpk ~ logk)
> panel.abline(coef=c(-4.847634, -1.037480)) # ->->-> This gets drawn
> panel.abline(coef=c(-4.847634, -1.037481)) # ->->-> This doesn't get drawn
> print(coef(lm.r)) # -4.847634 -1.349699 ; -3.377894 -1.498693
>
> } # end mypanel4loglog
>
> myprepanel4loglog<-
> function(x, # x is the variable column in melted data, equals the Network's ages
> y, # y is the value column in melted data, the degrees
> ... # Rest of the arguments
> )
> {
> FreqTable<- as.data.frame(table(y))
> FreqsVector<- sort(FreqTable$Freq)
> Min<- FreqsVector[1] # first element - the lowest value frequency
> # print(c(Max2, length(y)))
> list(ylim = c(log(Min / length(y)), 0), xlim = c(0, log(max(y)))) # log(p(k)) is always -ve as p(k) is decimal, so max(log(p(k)) is 0
> } # end myprepanel4loglog
>
> print(xyplot(value ~ variable | Range,
> data = md,
> xlab = "log(k); Panel = Range",
> ylab = "log(p(k))",
> main = "log(k) vs. log(p(k))",
> groups = Range,
> pch = 20, # dots instead of circles
> panel = mypanel4loglog,
> prepanel = myprepanel4loglog, # to set the scale of k and pk
> scales = list(x = (relation = "free"), y = (relation = "free")), # necessary to make x-axis in each panel adjustable according to k
> ))
>
>
More information about the R-help
mailing list