[R] Unintended behaviour (possibly bugs)

Jeff Newmiller jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Mon Feb 17 07:45:13 CET 2020


Dotplot is for raw data. You are giving it summarized data. I don't think it is appropriate to expect dotplot to undo your summarization for you in order to plot it.

On February 16, 2020 9:37:07 PM PST, Alexey Shipunov <dactylorhiza using gmail.com> wrote:
>P.S.
>
>I like also to defend my initial approach. Many help files said that:
>
>?pie: "Pie charts are a very bad way of displaying information. ... A
>bar chart or dot chart is a preferable way of displaying this type of
>data."
>
>?barplot: "See Also: ... ‘dotchart’ ..."
>
>?dotchart: "... Dot plots are a reasonable substitute for bar plots."
>
>However, if you plot the simple table, then:
>
>aa <- table(c(1, 1, 1, 2, 2, 3))
>barplot(aa) # no problems
>pie(aa) # no problems
>plot(aa, type="h") # no problems
>mosaicplot(aa) # no problems
>dotchart(aa) # warning: inappropriate object
>
>So R encourages users to use dot plots but repels them with a warning
>(especially bad looking on macOS GUI where warnings are in red). I
>think that Cleveland's plots should be promoted and therefore this
>warning is harmful.
>
>Of course, you can do something like
>
>dotchart(sapply(aa, as.numeric)) # no warning
>
>but I do not think that this complication is quite necessary.
>
>Alexey
>
>
>пн, 17 февр. 2020 г. в 13:59, Alexey Shipunov <dactylorhiza using gmail.com>:
>
>>
>> My suggestion (shipunov::Dotchart1()) was:
>>
>> ===
>>    yinch <- if (!is.null(ylab)) 0.4 else 0
>>    # inserted!
>>     if (!(is.null(labels) && is.null(glabels))) {
>>         nmai <- par("mai")
>>         nmai.2.new <- nmai[4L] + max(yinch + linch + goffset, ginch)
>+
>> 0.1 # changed!
>>         if (nmai.2.new > nmai[2L]) {
>>     # changed!
>>             nmai[2L] <- nmai.2.new
>>     # changed!
>>         }
>>         par(mai = nmai)
>>     }
>> ===
>>
>> But I am not sure if this is the best way.
>>
>> Now, how to move to r-devel? I never did it before.
>>
>> Alexey
>>
>> пн, 17 февр. 2020 г. в 13:54, Rui Barradas <ruipbarradas using sapo.pt>:
>> >
>> > Hello,
>> >
>> > Yes, this is definitely a bug.
>> > Even the matrix plot is puzzling, with a "1" as top row
>sort-of-label
>> > but no grid line. I'm trying to follow the source code of dotchart
>but
>> > am yet to understand exactly what it does to decide the margins
>settings.
>> >
>> >      if (!(is.null(labels) && is.null(glabels))) {
>> >        nmai <- par("mai")
>> >        nmai[2L] <- nmai[4L] + max(linch + goffset, ginch) +
>> >          0.1
>> >        par(mai = nmai)
>> >      }
>> >
>> > This should be moved to r-devel?
>> >
>> > Rui Barradas
>> >
>> > Às 03:33 de 17/02/20, Alexey Shipunov escreveu:
>> > > John and Rui, thanks!
>> > >
>> > > However, if we use the proper object, the problem still persists:
>> > >
>> > > dotchart(c("3"=1, "2"=2, "1"=3), ylab="Ylab") # ylab is invisible
>> > > dotchart(c("aa"=1, "b"=2, "cc"=3), ylab="Ylab") # ylab is partly
>visible (!!!)
>> > > dotchart(c("aaa"=1, "bbb"=2, "ccc"=3), ylab="Ylab") # ylab is
>well visible
>> > >
>> > > If the object is matrix, ylab is visible:
>> > >
>> > > dotchart(matrix(1:3, dimnames=list(c("aa","bb","cc"), NULL)),
>ylab="Ylab")
>> > >
>> > > But the ?dotchart explicitly says that "x: either a vector or
>matrix
>> > > of numeric values" and then "labels: a vector of labels for each
>> > > point.  For vectors the default is to use ‘names(x)’ ...".
>> > >
>> > > So this is likely a bug. Do you agree?
>> > >
>> > > Alexey
>> > >
>> > > пн, 17 февр. 2020 г. в 01:55, Rui Barradas
><ruipbarradas using sapo.pt>:
>> > >>
>> > >> Hello,
>> > >>
>> > >> I believe you are wrong, the error is not in dotchart, it's in
>your
>> > >> code. You assume that to plot an object of class "table" is the
>same as
>> > >> to plot an object of class "numeric".
>> > >>
>> > >> Inline.
>> > >>
>> > >> Às 12:21 de 16/02/20, Alexey Shipunov escreveu:
>> > >>> Dear list,
>> > >>>
>> > >>> I have been advised to share these with R-help instead of
>filling the
>> > >>> bug report:
>> > >>>
>> > >>> 1) dotchart() does not allow to see the left axis title
>('ylab') and
>> > >>> cannot change the left margin (outer margin 2) of the plot
>> > >>>
>> > >>> The code:
>> > >>>
>> > >>> aa <- table(c(1, 1, 1, 2, 2, 3))
>> > >>> dotchart(aa, ylab="Ylab") # does not show 'ylab'
>> > >>
>> > >> You are right, it does *not* show 'ylab' but the user is warned.
>> > >>
>> > >>
>> > >> aa <- table(c(1, 1, 1, 2, 2, 3))
>> > >> dotchart(aa, ylab = "Ylab") # does show 'ylab'
>> > >> #Warning message:
>> > >> #In dotchart(aa, ylab = "Ylab") :
>> > >> #  'x' is neither a vector nor a matrix: using as.numeric(x)
>> > >>
>> > >>
>> > >> My code:
>> > >>
>> > >>
>> > >> (mar <- par("mar"))    # new R session
>> > >> #[1] 5.1 4.1 4.1 2.1   # the left margin is 4.1
>> > >>
>> > >> aa <- as.numeric(table(c(1, 1, 1, 2, 2, 3)))
>> > >>
>> > >> dotchart(aa, ylab = "Ylab") # It does show 'ylab'
>> > >> old.par <- par(mar = mar + c(0, 5, 0, 0))
>> > >> par("mar")
>> > >> #[1] 5.1 9.1 4.1 2.1
>> > >>
>> > >> dotchart(aa, ylab = "Ylab")  # The left margin is now 9.1, much
>bigger
>> > >>
>> > >> par(old.par)                 # It does change the left margin
>> > >> dotchart(aa, ylab = "Ylab")  #  but only when a new graph is
>plotted.
>> > >>
>> > >>
>> > >>
>> > >>> old.par <- par(mar=c(1, 10, 1, 1)) ; dotchart(aa, ylab="Ylab")
>;
>> > >>> par(old.par) # does not change left margin
>> > >>>
>> > >>> Possible solution:
>> > >>>
>> > >>> I researched the problem and think that the dotchart() code
>will need
>> > >>> few corrections. If there is an interest, I can post it here;
>or you
>> > >>> can look at the code of shipunov::Dotchart1() function.
>> > >>>
>> > >>> 2) example(hist) includes two "wrong" and "extreme" examples
>which
>> > >>> slow down and even crash R on some systems; this make it
>unsuitable
>> > >>> for demonstration in the class and strikes beginners in R who
>just
>> > >>> want to understand how hist() works. Actually, I did it last
>week (I
>> > >>> was not aware of these examples), and in the class two
>computers hang,
>> > >>> and many others were extremely slow.
>> > >>>
>> > >>> The code:
>> > >>>
>> > >>> example(hist)
>> > >>>
>> > >>> Possible solution:
>> > >>>
>> > >>> If R maintainers will enclose parts of "hist" example in
>\dontrun{},
>> > >>> this will allow to see the code but in the same time will not
>strike
>> > >>> beginners in R who just
>> > >>> want to understand how hist() works. They will still be
>possible to
>> > >>> run with example(..., run.dontrun=TRUE).
>> > >>
>> > >> Agree, it's annoying. Sometimes there's a Warning section after
>the
>> > >> Details section. Maybe such a section could get users' attention
>to
>> > >> those examples? At least it wouldn't hurt...
>> > >>
>> > >>
>> > >> Hope this helps,
>> > >>
>> > >> Rui Barradas
>> > >>
>> > >>>
>> > >>> With best wishes,
>> > >>>
>> > >>> Alexey Shipunov
>> > >>>
>> > >>> ______________________________________________
>> > >>> 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
>http://www.R-project.org/posting-guide.html
>> > >>> and provide commented, minimal, self-contained, reproducible
>code.
>> > >>>
>> > >
>> > > ______________________________________________
>> > > 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
>http://www.R-project.org/posting-guide.html
>> > > and provide commented, minimal, self-contained, reproducible
>code.
>> > >
>
>______________________________________________
>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
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.



More information about the R-help mailing list