Plots seem merged when using `subplot` in `plotly`
未关闭
还没有人认领这个 Issue。
- 主要语言
- R
- 星标
- 2.7k
- 派生
- 641
- PR 合并指标
- 30 天内没有已合并 PR
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先运行提供的 R reprex 和 plotly::subplot,并检查随着图表数量增加,subplot 布局如何处理边距、间距和轴标签。当直方图在大型多图布局中仍保持视觉上的分隔且其标签清晰可读时,该 issue 即完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- plotly, r
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100