简体   繁体   中英

Boxplot next to a scatterplot in R with plotly

I created a scatter plot with plotly in R. Now I want to plot a boxplot with different data next to the scatter plot. I want to use plotly for this.

The result should look like this . Can someone help me please, I have no idea how to do that. My code so far is

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)

Here is an example on how to make a scatter with marginal box plots with plotly:

library(plotly)
data(iris)

create, three plots for the data: one for the scatter, two for the appropriate box plots, and one additional empty plot. Use the subplot function to arrange them:

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)

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM