旁边的散点图旁边的Boxplot与plotly

时间:2018-02-24 09:12:31

标签: r plotly boxplot r-plotly

我用R绘制了一个散点图。现在我想在散点图旁边绘制一个包含不同数据的箱线图。我想用这个来剧情。

结果应该看起来像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)

1 个答案:

答案 0 :(得分:0)

这是一个关于如何使用边缘框图进行散点图的示例:

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)

enter image description here