[英]Boxplot next to a scatterplot in R with plotly
我在 R 中用 plotly 创建了一个散点图。现在我想在散点图旁边绘制一个具有不同数据的箱线图。 我想为此使用 plotly。
结果应该是这样的。 有人可以帮我吗,我不知道该怎么做。 到目前为止我的代码是
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.