Bug 16953 - Vary plotting symbols in dotchart by group
Summary: Vary plotting symbols in dotchart by group
Alias: None
Product: R
Classification: Unclassified
Component: Graphics (show other bugs)
Version: R 3.3.*
Hardware: All All
: P5 enhancement
Assignee: R-core
Depends on:
Reported: 2016-06-21 09:20 UTC by Robert
Modified: 2016-06-21 09:20 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Robert 2016-06-21 09:20:55 UTC
The color parameter in dotchart allows the color of points to be varied by group, but attempting to vary pch by group gives unexpected results.  Varying plot symbol by group is potentially useful for colour blind users and for greyscale copies of published charts.  It is also easy to fix with the addition of one line in the code.

Currently the code for dotchart contains the following lines which allow color and lcolor to be varied by group:

    o <- sort.list(as.numeric(groups), decreasing = TRUE)
    x <- x[o]
    groups <- groups[o]
    color <- rep_len(color, length(groups))[o]
    lcolor <- rep_len(lcolor, length(groups))[o]

The addition of the following line would enable pch to be varied by group:

    pch <- rep_len(pch, length(groups))[o]

This should not cause any backwards compatibility issues, since an attempt to vary pch by group currently does not give useable results, and this change has no effect if a single pch is specified.  In addition, the documentation arguably implies that only a single pch is currently supported (For the color argument the documentation states "the color(s) to be used for points and labels.", whereas for the pch argument:  "the plotting character or symbol to be used.").  Adding support for multiple symbols as well as colour would be a simple and useful enhancement.

The following is a reproducible example.  This shows the problem, and can also be used to demonstrate that the addition of the line of code described gives the expected output:

    foo <- data.frame(Specimen=paste("Specimen", 1:18),
                  Group=c(rep("Benign", 4),
                          rep("In-situ", 6), 
                          rep("Invasive", 8)),
                  Outcome=rweibull(18, 5) + (1:18 / 18))
    with(foo, dotchart(Outcome, 
         groups = Group,
         color = c("green", "orange", "red")[Group],
         pch = c(16, 15, 17)[Group], 
         xlab = "Outcome measure /bar", 
         labels = Specimen))