在 ggplot2 图上使用 ggplotly 不适用于箱线图可变宽度或离群值形状变化
Using ggplotly on a ggplot2 graph does not work with boxplot variable width or outliers shape change
当我在 ggplot2 图表上使用 ggplotly 时,ggplot2 的一些功能被重置。
代码示例:
library(tidyverse)
db <- iris
# Changing the N in one of the categories for the example:
db$Sepal.Length[1:40] <- NA
p <- db %>% ggplot(aes(Species, Sepal.Length)) +
geom_boxplot(varwidth = TRUE, outlier.shape = NA)
p
当使用 ggplotly(p) 时,varwidth 选项不起作用,圆的异常值形状 returns。这是 ggplolty 的固有品质吗?如果是这样,我如何在 ggplotl2 中获得这些选项?
谢谢!
Plotly 似乎确实没有继承所有 ggplot 参数。至少可以按照此线程更改异常值:https://github.com/ropensci/plotly/issues/1114
library(tidyverse)
library(plotly)
p <- iris %>% ggplot(aes(Species, Sepal.Length)) +
geom_boxplot()
# Need to modify the plotly object and make outlier points have opacity equal to 0
p <- plotly_build(p)
for(i in 1:length(p$x$data)) {
p$x$data[[i]]$marker$opacity = 0
}
p
异常值已删除。我不确定是否可以将 var.width
包含在 plotly boxplots 中。
我不确定 var.width
是否真的有助于可视化 - 包括我在内的很多人都不太擅长比较条形的宽度......为了比较样本量,实际显示值可能会更清楚,例如geom_jitter
:
p <- db %>% ggplot(aes(Species, Sepal.Length)) +
geom_boxplot() +
geom_jitter(width = 0.2)
ggplotly(p)
当我在 ggplot2 图表上使用 ggplotly 时,ggplot2 的一些功能被重置。
代码示例:
library(tidyverse)
db <- iris
# Changing the N in one of the categories for the example:
db$Sepal.Length[1:40] <- NA
p <- db %>% ggplot(aes(Species, Sepal.Length)) +
geom_boxplot(varwidth = TRUE, outlier.shape = NA)
p
当使用 ggplotly(p) 时,varwidth 选项不起作用,圆的异常值形状 returns。这是 ggplolty 的固有品质吗?如果是这样,我如何在 ggplotl2 中获得这些选项?
谢谢!
Plotly 似乎确实没有继承所有 ggplot 参数。至少可以按照此线程更改异常值:https://github.com/ropensci/plotly/issues/1114
library(tidyverse)
library(plotly)
p <- iris %>% ggplot(aes(Species, Sepal.Length)) +
geom_boxplot()
# Need to modify the plotly object and make outlier points have opacity equal to 0
p <- plotly_build(p)
for(i in 1:length(p$x$data)) {
p$x$data[[i]]$marker$opacity = 0
}
p
异常值已删除。我不确定是否可以将 var.width
包含在 plotly boxplots 中。
我不确定 var.width
是否真的有助于可视化 - 包括我在内的很多人都不太擅长比较条形的宽度......为了比较样本量,实际显示值可能会更清楚,例如geom_jitter
:
p <- db %>% ggplot(aes(Species, Sepal.Length)) +
geom_boxplot() +
geom_jitter(width = 0.2)
ggplotly(p)