"scale_y_log" with "jitter_dodge" misbehavior (using color to create 3 plots at one x value)
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 7k
- Forks
- 2.1k
- Avg merge
- 59m
- Merged PRs (30d)
- 2
Description
Hello! I have this plot in a Shiny app and so there are a lot of possibly combinations and one of my users pointed this out to me today. In the Real World this x axis is timepoints, and I've just pulled one out for the reprex.
Basically, for a given x value, I want 3 boxplots so I used aes(color) to make them. When one of my factors only has zero as a value, and I apply a log10 transform (thus creating a -Inf) it throws off the x position of the dodge. This does not happen when x and color are the same value.
library(reprex)
library(ggplot2) # ggplot2_3.3.2
df <- data.frame(cat_id = as.character(1:22),
species = "cat",
color = c("tabby", rep("tortie", 20), rep("black", 1)),
floofiness = c(runif(21, 1, 10), 0),
nose_warmth = c(runif(22, 1, 10)))
Expected behavior
# y = floofiness (only black value = 0)
ggplot(df, aes(x = species, y = floofiness, color = color)) +
geom_boxplot(outlier.shape = NA) +
geom_point(position = position_jitterdodge(jitter.width = .1)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))

# y = nose_warmth (no zeroes) + log
ggplot(df, aes(x = species, y = nose_warmth, color = color)) +
geom_boxplot(outlier.shape = NA) +
geom_point(position = position_jitterdodge(jitter.width = .1)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
scale_y_log10()

Not expected behavior
# y = floofiness (only black value = 0) + log
ggplot(df, aes(x = species, y = floofiness, color = color)) +
geom_boxplot(outlier.shape = NA) +
geom_point(position = position_jitterdodge(jitter.width = .1)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
scale_y_log10() # this is the only difference
#> Warning: Transformation introduced infinite values in continuous y-axis
#> Warning: Transformation introduced infinite values in continuous y-axis
#> Warning: Removed 1 rows containing non-finite values (stat_boxplot).

Created on 2020-10-30 by the reprex package (v0.3.0)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied reprex with ggplot(), geom_boxplot(), geom_point(), position_jitterdodge(), and scale_y_log10(). Inspect how position_jitterdodge handles the zero-valued group after the log transformation. Done means the three color groups retain their expected x positions when one group contains only zero values, without introducing this dodge misbehavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100