我正在为每个群集设置一个栏。我需要每个条形的高度为每个邮政编码中的平均值(基于人口)。然后,我想要所有拉链的平均值的水平虚线。
## Data
df <- data.frame(
zipcode=c("10001","10002","10003","10004","10005","10006","10007","10008","10009","10010"),
black= c(2,3,4,6,7,8,9,11,13,15),
white = c(6,8,12,14,15,16,14,14,14,22),
population = c(11,22,33,44,55,66,77,88,99,100),
female = c(5,11,32,22,31,21,44,11,22,14),
cluster = c("1","2","3","2","2","1","3","3","3","1"))
print(df)
> print(df)
zipcode black white population female cluster
1 10001 2 6 11 5 1
2 10002 3 8 22 11 2
3 10003 4 12 33 32 3
4 10004 6 14 44 22 2
5 10005 7 15 55 31 2
6 10006 8 16 66 21 1
7 10007 9 14 77 44 3
8 10008 11 14 88 11 3
9 10009 13 14 99 22 3
10 10010 15 22 100 14 1
如果我尝试按%white制作群集的条形图。 白人的总体平均值为23%,这是一条水平虚线。
类别1的总体平均白人为24% 群集2的总体平均白人为30.5% 第3组的整体白人平均水平为18%