Plots seem merged when using `subplot` in `plotly`
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
Description:
When attempting to display multiple histograms using subplot from the plotly package, the plots appear merged together, making them difficult to distinguish. This issue is primarily reproducible when there are large number of visualizations to plot together.
Here is a minimal reprex for the same:
# Load necessary libraries
library(ggplot2)
library(plotly)
# set seed for reproducibility
set.seed(123)
# simulate a dataset
simulateDataset <- function(numRows = 100, numCols = 40) {
data <- data.frame(matrix(nrow = numRows, ncol = numCols))
for (i in 1:numCols) {
if (i %% 2 == 0) {
data[[i]] <- rnorm(numRows, mean = 50, sd = 10) # Normal distribution
} else {
data[[i]] <- rexp(numRows, rate = 0.1) # Exponential distribution
}
}
names(data) <- paste0("Var", 1:numCols)
return(data)
}
# simulate the data
df <- simulateDataset(numRows = 100, numCols = 60)
# create histograms and convert to plotly
plotList <- lapply(names(df), function(colName) {
if (is.numeric(df[[colName]])) {
p <- ggplot(df, aes(x = .data[[colName]])) +
geom_histogram(binwidth = 0.5, fill = 'grey', color = 'black') +
theme_minimal()
ggplotly(p)
}
})
# define number of rows based on number of plots in each row
numberOfRows <- ceiling(length(plotList) / 3)
# display all plots together using subplot
subplot(plotList, nrows = numberOfRows, margin = 0.05, titleX = TRUE, titleY = TRUE)
Expected Behavior:
Each histogram should be clearly separated from the others, with appropriate spacing and labels visible.
Screenshot
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 R reprex with plotly::subplot and inspect how the subplot layout handles margins, spacing, and axis labels as the number of plots grows. The issue is done when the histograms remain visually separated and their labels are readable in the large multi-plot arrangement.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- plotly, r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100