【发布时间】:2023-03-29 12:51:01
【问题描述】:
当使用 plotly(在 R 中)时,在组合子图后,仍然有一个未使用和空白的子图。我使用下面的 ggplot2 数据集mpg 重新创建了该问题。
library(dplyr)
library(ggplot2)
library(plotly)
audi <- mpg %>%
filter(manufacturer == "audi")
chevy <- mpg %>%
filter(manufacturer == "chevrolet")
fig1 <- plot_ly(audi, x = ~hwy, y = ~year, name = "", type = 'scatter',
mode = "markers", marker = list(color = "blue", symbol = 'x-dot'))
fig2 <- plot_ly(chevy, x = ~hwy, y = ~year, name = "", type = 'scatter',
mode = "markers", marker = list(color = "red", symbol = 'circle'))
fig <- subplot(fig1, fig2)
fig <- fig %>% subplot(shareX = TRUE,shareY = TRUE,which_layout = "merge")
fig <- fig %>% layout(
title = "Audi and Chevy",
xaxis = list(title = "Highway MPG"),
yaxis = list(title = "Year"),
margin = list(l = 100)
)
我能找到的唯一解决方案是修改使用的子图的宽度,但这会在右侧留下相当多未使用的空白区域,并导致标题远离右侧(因为它调整到已使用和未使用的子图的中心)。
有没有办法删除未使用的子图?如果没有,有没有办法组织/子集数据框,以便一开始只需要使用一个图?
谢谢!
【问题讨论】: