如何在直方图中去除低频箱
假设我有一个数据框架,其中包含一个数字数组,我想在直方图中可视化。我要实现的是仅显示包含更多的垃圾箱,而不是说50个观察结果。
步骤1
set.seed(10)
x <- data.frame(x = rnorm(1000, 50, 2))
p <-
x %>%
ggplot(., aes(x)) +
geom_histogram()
p
步骤2
pg <- ggplot_build(p)
pg$data[[1]]
作为检查当我打印pg $ data [[1]]
i'时d喜欢只有<代码> count&gt; = 50 的行。
谢谢
Let's say I've a data frame containing an array of numbers which I want to visualise in a histogram. What I want to achieve is to show only the bins containing more than let's say 50 observations.
Step 1
set.seed(10)
x <- data.frame(x = rnorm(1000, 50, 2))
p <-
x %>%
ggplot(., aes(x)) +
geom_histogram()
p
Step 2
pg <- ggplot_build(p)
pg$data[[1]]
As a check when I print the pg$data[[1]]
I'd like to have only rows where count >= 50
.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用此代码,您可以看到已删除的垃圾箱的计数:
With this code you can see the counts of the deleted bins:
您可以做这样的事情,很可能您真的不喜欢X轴上的分解名称,但是您可以做的就是将两个值分开,并以平均值为例绘制X轴。
You could do something like this, most likely you do not really like the factorized names on the x-axis, but what you can do is split the two values and take the average to take that one to plot the x-axis.