r - 如何根据 r 中 cut 函数的 bin 为单个变量做 multiboxplot?
问题描述
我正在尝试根据 cut 函数中的 bin 数量为变量创建多框图
movie_reg %>% select(Collection) %>% pull() %>% cut(7)
[1] (3.57e+04,4.86e+04] (3.57e+04,4.86e+04] (6.14e+04,7.43e+04] (6.14e+04,7.43e+04] (6.14e+04,7.43e+04]
[6] (4.86e+04,6.14e+04] (3.57e+04,4.86e+04] (3.57e+04,4.86e+04] (2.29e+04,3.57e+04] (3.57e+04,4.86e+04]
[11] (2.29e+04,3.57e+04] (3.57e+04,4.86e+04] (3.57e+04,4.86e+04] (3.57e+04,4.86e+04] (3.57e+04,4.86e+04]
.
.
[501] (2.29e+04,3.57e+04] (3.57e+04,4.86e+04] (3.57e+04,4.86e+04] (3.57e+04,4.86e+04] (3.57e+04,4.86e+04]
[506] (3.57e+04,4.86e+04]
7 Levels: (9.91e+03,2.29e+04] (2.29e+04,3.57e+04] (3.57e+04,4.86e+04] (4.86e+04,6.14e+04] ... (8.71e+04,1e+05]
我不确定我将如何在箱线图中将级别和相应的值传递给它。以下是我尝试过但出现错误的方法:
movie_reg %>% select(Collection) %>% pull() %>% cut(7) %>% boxplot(aes(x=levels))
Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) : 'x' must be atomic
解决方案
如果您提供一个可重现的示例会更好,现在很难帮助您。我确实注意到您在 boxplot 函数中使用了美学,但美学是 ggplot 的一部分,而不是基本函数boxplot()
。此外,在多箱图中,您需要提供 x 和 y,所以也许您只需要一个显示每组计数的条形图(只需要一个 x)?
movie_reg %>%
select(Collection) %>%
pull() %>%
cut(7) %>%
ggplot(aes(x=levels)) +
geom_bar()
推荐阅读
- php - PHP exec wget nohup 并写入实时登录
- windows-10 - pyconfig.h(59) 致命错误 C1083:无法打开包含文件:'io.h':没有这样的文件或目录
- c# - 使用 C# 检查文件是否正在使用
- c# - Unity c# - 我怎样才能做到这一点,以便我可以通过一个类访问我的所有其他类、变量和方法?
- c# - 如何经常将图像保存到 Windows 窗体 (C#) 中的文件?
- c# - C# 如果 int 值增加/增加 5 或特定值,则执行某些操作
- vb.net - 如何停止表单的 Load 事件处理程序跳过某些语句
- vue.js - 无法在 Vuejs 中访问 ag-Grid API
- javascript - 在 Electron 中使用 window.document.write()
- javascript - 为什么 .get() 在我的不和谐机器人代码中不起作用?