r - 在 ggplot2 图表上使用 ggplotly 不适用于箱线图可变宽度或异常值形状变化
问题描述
当我在 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 选项不起作用,并且圆形的异常形状返回。这是 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
在情节箱图中。
我不确定是否var.width
真的有助于可视化- 包括我自己在内的许多人在比较条形宽度方面并不是很好......为了比较样本量,实际显示值可能更清楚,例如geom_jitter
:
p <- db %>% ggplot(aes(Species, Sepal.Length)) +
geom_boxplot() +
geom_jitter(width = 0.2)
ggplotly(p)
推荐阅读
- java - 特定 API 春季启动的基本身份验证 - 返回 200 ok 但意外正文
- node.js - SyntaxError: 意外的标记 ';' 在
在编译 ejs 时 - powershell - 在 windows 10 powershell 中使用 sqlplus 执行 sql 文件
- javascript - 使用 selenium 跟踪 html 元素的变化
- git - 当我使用 git add 时。命令它不断向我显示警告
- vue.js - 深度嵌套数组的 b 表项
- keystonejs - Keystone.js 6 访问被拒绝 adminMeta
- angular - 根目录下的 Angular GitHub 页面应用程序隐藏了项目页面应用程序
- firebase - 群聊到私人聊天 Whatsapp 之类的功能
- postgresql - 如何正确编写 PSQL 函数以将列名放入 postgresql 函数结果