r - 忽略 ggplot 中 geom_bar 和 geom_histogram 中的异常值
问题描述
我有数据框
DF <- data.frame(respondent = factor(c(1, 2, 3, 4, 5, 6)), choice = as.numeric(c(1, 3, 3, 5, 10, 1000)))
当我绘制它时,“1000”值使情节难以解释:
library(ggplot2)
ggplot(DF, aes(choice, 1, ymax=10))+
geom_bar(stat = "identity")+
scale_y_continuous (limits = quantile(DF$choice, c(0, 10)
theme(axis.text.x = element_text(angle = 0, hjust = 1),
text = element_text(size=20))
如何从图中删除异常值?是否有一个相当于ylim
我可以简单地设置为“10”的ggplot?有一篇关于处理异常值的帖子geom_boxplot
,但我无法获得在geom_bar
或中工作的解决方案geom_histogram
。
解决方案
我想xlim
这就是你要找的吗?
ggplot(DF, aes(choice, 1)) +
geom_bar(stat = "identity") +
xlim(c(0, 11))
您将收到警告Warning message: Removed 1 rows containing missing values (position_stack).
,指出由于施加的限制,数据点已被删除。
我删除了其他代码以使其成为“最小示例”-如果这对您的问题很重要,请随时跟进。
推荐阅读
- java - GridLayout 不通过按钮单击添加组件?
- upload - 如何处理 Selenium 中用于上传文件夹/文件的机器人类的限制?
- asp.net-core - 强制注销使用身份服务器4,例如您登录的 facebook
- javascript - 使用 jQuery 按顺序加载多个脚本文件并延迟 - 结合找到的两个函数
- java - GWT 对 Android LinearLayout 的 layout_weight 属性的模拟?
- python - 如何在 Python 中使子进程超时
- python - ImportError:无法导入名称 model_fn:Tensorflow
- xml - 努力创建相关的 XSLT 文件以转换为 Access
- python - 向量化数组操作,轮流排除数组元素
- node.js - nodejs ts 管理共享变量