[R] lattice log scale labels.

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Thu Sep 5 16:54:00 CEST 2024


Do the "at" and "labels" components of the "scales" list argument to xyplot
not do what you want?

Cheers,
Bert

On Thu, Sep 5, 2024 at 4:05 AM Gerrit Draisma <gdraisma using xs4all.nl> wrote:

> Dear R-helpers,
>
> In the plot below I would like to have labels at positions 2^(3*(0:10)),
> and keep the labels in the exponential format.
> I tried using yscale.components.default.
>
> *This* gives the right format of the labels:
> --------
>  > yscale.components.default(lim= c(0,30),log=2)
> ....
> $num.limit
> [1]  0 30
> ...
> [1]  0  5 10 15 20 25 30
> ...
> $left$labels$labels
> [1] "2^0"  "2^5"  "2^10" "2^15" "2^20" "2^25" "2^30"
> --------
>
> and *this* gives the right locations
> --------
>  > yscale.components.default(lim= c(0,30),log=2,at=2^(3*(0:10)))
> $num.limit
> [1]  0 30
> ...
>   [1]  0  3  6  9 12 15 18 21 24 27 30
> ...
> $left$labels$labels
>   [1] "1"          "8"          "64"         "512"        "4096"
>   [6] "32768"      "262144"     "2097152"    "16777216"   "134217728"
> [11] "1073741824"
> --------
>
> How can I get the format in the first example at the locations of the
> second?
>
> Thanks,
> Gerrit
>
> -------------
> x <- read.csv(text="
> n,c,t,u
> 4,1,2,1
> 8,28,8,1
> 12,495,42,3
> 16,8008,256,7
> 20,125970,1680,31
> 24,1961256,11640,138
> 28,30421755,83776,808
> 32,471435600,620576,4956
> 36,7307872110,4700880,33719")
> library(lattice)
> yscale.components.log2 <- function(...){
>      ans <- yscale.components.default(...)
>      ans$left$labels$labels <-
>          parse(text = ans$left$labels$labels)
>      ans
> }
>
>
> # pdf("tangle_mathFig06.pdf")
> xyplot(c+t+u~n,data=x,type="b", xlab="Size", ylab="Number of tangles",
>     scales=list(x=list(at=4*(1:9)),y=list(log=2)),
>     yscale.components=yscale.components.log2,
>     auto.key=list(columns=3,text=c("(choose m n)","tangles","unique
> tangles"),
>     points=FALSE,lines=TRUE))
> # dev.off()
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> https://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list