Skip to content

Inconsistencies between type_points and type_lines #679

Description

@zeileis

Overview:

Trying to combine type = "h" and type = "p" (while reviewing #678), I found the following inconsistencies between type_points and type_lines when using character or factor variables:

  1. type_points orders the axis by the order of the levels while type_lines uses the order of the observations.
  2. type_lines loses the character labels when type != "p" and flip = TRUE.

Item 2 is clearly a bug in type_lines.

For item 1 one could justify both approaches. I guess that the approach of type_points is the more consistent one. However, for the case of a character variable where each character value occurs exactly once (as in the example below), the behavior of type_lines is what I would have expected first. I'm not sure whether there is a non-confusing way of enabling both.

Data:

Data frame with a character variable where the ordering in the data is different from the lexicographical ordering (that is used for the default factor levels).

LOTR <- data.frame(
  name = c("The Fellowship of the Ring", "The Two Towers", "The Return of the King"),
  runtime = c(178, 179, 201)
)

(All examples below would remain the same if LOTR$name <- factor(LOTR$name) were used.)

Problem 1: Observation order

tinyplot(runtime ~ name, data = LOTR, type = type_points())
tinyplot(runtime ~ name, data = LOTR, type = type_lines(type = "p"))
Image

As argued above, I find the ordering of type_lines more intuitive in this example, where every character label only occurs once. To get the same in type_points I would have to use factor(name, levels = name) which seems a bit heavy for such a simple plot. However, if there were more variables or repeated labels, this is not so clear anymore. In that case, the principled factor levels solution is probably safer.

Problem 2: Axis character labels

tinyplot(runtime ~ name, data = LOTR, type = type_points(), flip = TRUE)
tinyplot(runtime ~ name, data = LOTR, type = type_lines(type = "b"), flip = TRUE)
Image

Interestingly, the problem with the axis labels does not occur for type_lines(type = "p").

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions