R 中散点图旁边的箱线图 plotly

Boxplot next to a scatterplot in R with plotly

我在 R 中用 plotly 创建了一个散点图。现在我想在散点图旁边绘制一个包含不同数据的箱线图。我想为此使用情节。

结果应该类似于 this。有人可以帮我吗,我不知道该怎么做。 到目前为止我的代码是

plot_ly(ds, x = ~x, y = ~y , mode = "markers", name = "Clusters", opacity = point.opacity, 
           text = ds$id,
           hoverinfo = "text",
           marker = list(symbol = point.symbol, color = ~color, size = point.size, 
                         line = list(color = "#262626", width = point.linewidth, opacity = point.lineopacity)),
           showlegend = F)

下面是一个关于如何使用 plotly 绘制边缘箱形图的散点图的示例:

library(plotly)
data(iris)

为数据创建三幅图:一幅用于散点图,两幅用于适当的箱形图,另外一幅为空图。使用subplot函数来排列它们:

subplot(
  plot_ly(data = iris, x = ~Petal.Length, type = 'box'),
  plotly_empty(),
  plot_ly(data = iris, x = ~Petal.Length, y = ~Petal.Width, type = 'scatter',
          mode = 'markers'),
  plot_ly(data = iris, y = ~Petal.Width, type = 'box'),
  nrows = 2, heights = c(.2, .8), widths = c(.8,.2), margin = 0,
  shareX = TRUE, shareY = TRUE) %>%
  layout(showlegend = F)