[R] graphical behavior of a table of numbers

Bert Gunter bgunter.4567 at gmail.com
Sun Jan 29 01:19:37 CET 2017


Rich:

Simpler: Just lose the "table" class.

plot(as.numeric(names(fr)), as.vector(fr),  type="h",
            xlab="Determinant", ylab="Frequency")


However, I'm no less puzzled by the "strange" behavior than you.

In addition, it's probably worth noting that xyplot in lattice (and no
doubt ggplot,too) does not have this problem (as I'm sure you know):

xyplot(fr ~ as.numeric(names(fr)),  type="h",
            xlab="Determinant", ylab="Frequency")


Cheers,
Bert
Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sat, Jan 28, 2017 at 3:03 PM, Richard M. Heiberger <rmh at temple.edu> wrote:
> ## This example is from R-intro.pdf page 21 (R-3.3.2)
>
> d <- outer(0:9, 0:9)
> fr <- table(outer(d, d, "-"))
> plot(as.numeric(names(fr)), fr, type="h",
>             xlab="Determinant", ylab="Frequency")
> ## The y-axis tick marks are at c(-21,24,65).
> ## This seems to be because class(fr) == "table"
>
> ## Switching the class to array gives the more appropriate
> ## y-axis ticks at seq(0,500,100) .
>
> fr.array <- fr
> class(fr.array) <- "array"
> plot(as.numeric(names(fr)), fr.array, type="h",
>             xlab="Determinant", ylab="Frequency")
>
>
> ## I have a question and a recommendation.
> ## Question:
> ## Why are the y-axis ticks for the table defaulted to c(-21,24,65).
> ##
> ## Recommendation:
> ## Changed the example on page 21 to show the ticks at seq(0,500,100)?
>
> ## Rich
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list