[英]How to remove whiskers from geom_boxplot() when called from a ggplotly() function
How do I get it so that it returns a box-plot without upper & lower whiskers?我如何获得它以使其返回没有上下胡须的箱线图? When I run this:
当我运行这个:
a <- ggplot(df1, aes(Name, Values)) +
geom_violin(width = 6, alpha = 0.5, trim = FALSE) +
geom_boxplot(width = 1, fill = "black", colour = "black", alpha = 0.5) +
geom_jitter(size = 1, alpha = 0.5) +
stat_summary(fun = mean, geom = "point", shape = 6, alpha = 0.5) +
theme(panel.grid.major.x = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank()) +
ggtitle(label = "Title of Plot")
a
I get a boxplot without upper & lower whiskers.我得到一个没有上下胡须的箱线图。 However when I run this:
然而,当我运行这个:
ggplotly(a)
I get a boxplot with upper & lower whiskers.我得到一个带有上下胡须的箱线图。 I require the plot to be interactive, but I want to remove the upper & lower whiskers.
我要求 plot 是交互式的,但我想移除上下胡须。 How would I do this?
我该怎么做?
Other than starting in Plotly or removing the whiskers in ggplot
, you can change them by modifying the ggplotly
object whiskerwidth
for each type = "box"
trace.除了从 Plotly 开始或删除
ggplot
中的胡须之外,您可以通过修改ggplotly
whiskerwidth
胡须宽度来更改它们,每个type = "box"
跟踪。
plt <- ggplotly(a) # create a ggplotly object
invisible(lapply(1:length(plt$x$data),
function(k) { # ensure it's a box trace
if(isTRUE(plt$x$data[[k]]$type == "box")) {
plt$x$data[[k]]$whiskerwidth <<- 0 # no width whiskers
}
}))
plt # check out the change
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.