gpt4 book ai didi

r - 使用 R plotly 中的标记将抖动添加到分组箱线图

转载 作者:行者123 更新时间:2023-12-01 01:47:50 25 4
gpt4 key购买 nike

我想要 互动 (这意味着可以使用框/套索选择来选择它们)抖动点显示在 分组箱线图 .我是从这个问题出来的:Add jitter to box plot using markers in plotly .我想要完全相同,但箱线图应该分组。

我做了一个箱线图,但点都混淆了:

dat %>%
plot_ly(x = ~as.numeric(IC),
y = ~xval,
color = ~gene,
type = "box",
hoverinfo = "none",
boxpoints = FALSE
) %>%
add_markers(x = ~jitter(as.numeric(IC)),
y = ~xval,
color = ~gene,
marker = list(size = 3),
hoverinfo = "text",
text = txt,
showlegend = TRUE) %>%
layout(boxmode = "group")

enter image description here

当我尝试将 X 轴按因子分组(这样每个组合都是一个级别)时,我无法将我的箱线图分组:
dat <- dat %>% 
mutate(gene_x_covariate = as.factor(
paste0(get(facet_title), "-", gene)))

dat %>%
plot_ly(x = ~as.numeric(gene_x_covariate),
y = ~xval,
color = ~gene,
type = "box",
hoverinfo = "none",
boxpoints = FALSE
) %>%
add_markers(x = ~jitter(as.numeric(gene_x_covariate)),
y = ~xval,
color = ~gene,
marker = list(size = 3),
hoverinfo = "text",
text = txt,
showlegend = TRUE) %>%
layout(boxmode = "group")

enter image description here

当我尝试在 X 轴上混合变量时,我从箱线图中得到了点:
dat %>%
plot_ly(x = ~as.numeric(IC),
y = ~xval,
color = ~gene,
type = "box",
hoverinfo = "none"
) %>%
add_markers(x = ~jitter(as.numeric(gene_x_covariate)),
y = ~xval,
color = ~gene,
marker = list(size = 3),
hoverinfo = "text",
text = txt,
showlegend = TRUE) %>%
layout(boxmode = "group")

enter image description here

有任何想法吗?

最佳答案

boxpoints 对你有用吗? See this
您可以通过 pointpos 参数移动这些点。

iris %>% 
plot_ly(x = ~cut( Sepal.Length, breaks = 4),
y = ~Petal.Width,
color = ~Species,
type = "box",
marker = list( size = 10),
boxpoints = "all",
jitter = 0.4,
pointpos = 0,
hoverinfo = "all"
) %>% layout( boxmode = "group")

关于r - 使用 R plotly 中的标记将抖动添加到分组箱线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47286911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com