首页 > 解决方案 > 在geom_rect中放置一定数量的点

问题描述

我有以下数据:

set.seed(1)
df <- data.frame(ID = c(1:123), 
                 value = rnorm(123, mean = 30))

我准备情节

ggplot (df) +
  geom_rect(aes(xmin = 0, xmax = 100, ymin = 28.4, ymax =31.6), 
            fill = "lightcoral", alpha = 0.006) +
  geom_point(aes(x=ID, y = value), color = "red3") 

如何确定(计算)y min 和 y max 以使 80% 的点位于该区域的中间?当然,一个区域可能包含 98 个点(在本例中)。

标签: rggplot2

解决方案


推荐阅读