所以我有这个数据
>Survey[1:4]
# A tibble: 268 x 4
Horodateur Gender Age Time
<dttm> <chr> <chr> <chr>
1 2021-04-23 09:59:16 Male [18,24[ 1-5 hours
2 2021-04-23 10:11:35 Female [10,18[ 1-5 hours
3 2021-04-23 10:18:24 Male [18,24[ >10 hours
4 2021-04-23 10:42:28 Female [18,24[ 5-10 hours
5 2021-04-23 10:42:37 Female [18,24[ 5-10 hours
6 2021-04-23 10:45:35 Female [24,34[ 1-5 hours
7 2021-04-23 10:48:09 Male [18,24[ 5-10 hours
8 2021-04-23 10:49:56 Male [18,24[ 5-10 hours
9 2021-04-23 10:50:39 Male [24,34[ 0 hours
10 2021-04-23 10:51:36 Male [18,24[ 5-10 hours
# ... with 258 more rows
> str(Survey[1:4])
tibble [268 x 4] (S3: tbl_df/tbl/data.frame)
$ Horodateur: POSIXct[1:268], format: "2021-04-23 09:59:16" "2021-04-23 10:11:35" ...
$ Gender : chr [1:268] "Male" "Female" "Male" "Female" ...
$ Age : chr [1:268] "[18,24[" "[10,18[" "[18,24[" "[18,24[" ...
$ Time : chr [1:268] "1-5 hours" "1-5 hours" ">10 hours" "5-10 hours" ...我写了这个条形码
A=sum(Survey$Age =="[10,18[")
B=sum(Survey$Age =="[18,24[")
C=sum(Survey$Age =="[24,34[")
D=sum(Survey$Age =="[34,65[")
Age_vector=c(A,B,C,D)
colors=c("#555b6e","#89b0ae","#bee3db","#ffd6ba")
b <- barplot(table(Survey$Age),col=colors,ylim=c(0,250))

现在,,我想在每个条子上添加计数数( Age_vector ),我希望将间隔改为“< 18”这样的文本,而不是“[10,18][]
我试着在ggplot上做,但我做不到。
发布于 2021-06-03 19:01:27
基本图形:
tb <- table(mtcars$cyl)
tb
# 4 6 8
# 11 7 14
bp <- barplot(tb)
text(bp[,1], tb-1, tb)

https://stackoverflow.com/questions/67827229
复制相似问题