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:
type_points orders the axis by the order of the levels while type_lines uses the order of the observations.
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"))
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)
Interestingly, the problem with the axis labels does not occur for type_lines(type = "p").
Overview:
Trying to combine
type = "h"andtype = "p"(while reviewing #678), I found the following inconsistencies betweentype_pointsandtype_lineswhen using character or factor variables:type_pointsorders the axis by the order of the levels whiletype_linesuses the order of the observations.type_linesloses the character labels whentype != "p"andflip = 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_pointsis 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 oftype_linesis 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).
(All examples below would remain the same if
LOTR$name <- factor(LOTR$name)were used.)Problem 1: Observation order
As argued above, I find the ordering of
type_linesmore intuitive in this example, where every character label only occurs once. To get the same intype_pointsI would have to usefactor(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
Interestingly, the problem with the axis labels does not occur for
type_lines(type = "p").