ggplotly doesn't display geom_rect with ymin = -Inf and ymax = Inf
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
In ggplot::geom_rect(), one can specify the aesthetics ymin = -Inf and ymax = Inf, which will draw the rectangles to the limit of the plotting area. Apparently, ggplotly does not support this behaviour, and will fail to display the rectangles when a ggplot object with such a geom_rect is passed.
Motivation This behaviour of geom_rect is especially useful for indicating time periods of interest when plotting time series. Workarounds such as manually specifying the ymin and ymax limits to mimic the behaviour are much less effective: it can be difficult to know in advance what those limits should be, and they are affected by expand settings in the scale specification.
# Plot definition
example_plot = economics %>%
ggplot() +
geom_line(aes(x = date, y = psavert)) +
geom_rect(data = data.frame(xmin = seq(as.Date('1970-01-01'),
as.Date('2010-01-01'),
'10 years'),
xmax = seq(as.Date('1975-01-01'),
as.Date('2015-01-01'),
'10 years'),
ymin = -Inf, ymax = Inf),
aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax))
# Base ggplot object
example_plot

# Calling ggplotly
example_plot %>% ggplotly()

Note ggplotly image above captured using 'export' function on Viewer pane in RStudio.
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 provided economics and geom_rect example through ggplotly(), then trace the ggplotly conversion entry point for geom_rect. Compare the base ggplot and rendered output; done means rectangles with ymin = -Inf and ymax = Inf display to the plotting-area limits.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- plotly, r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100