【发布时间】:2019-10-19 15:39:24
【问题描述】:
我有一个相对较大的数据集,我正在尝试将其绘制到 R 中。这就是我的数据集的 sn-p 的样子
> dat
Who Activity Duration
1 Ch Stationary 14
2 Ch Stationary 18
3 Ch Interaction 2
4 Ch Stationary 6
5 Ch Interaction 1
6 Ch Display 10
7 Ch Interaction 6
8 Ch Stationary 5
9 Ch Stationary 20
10 Ch Stationary 13
11 Ch Stationary 17
12 Co Interaction 3
13 Co Stationary 31
14 J Stationary 8
15 R OOS 1
16 R Interaction 1
17 J OOS 4
我正在尝试使用持续时间作为百分比来构建堆积条形图,而不仅仅是原始值。到目前为止,这是我想出的:
p7 <- ggplot() +
geom_bar(aes(y= dat$Duration, x= dat$Who, fill = dat$Activity),
stat ="identity")
p7 <- p7 + scale_fill_brewer(palette="Set3")
p7 <- p7 + xlab("Chimp ID") + ylab ("Total Time Spent (min)")
p7 <- p7 + labs(fill = "Behaviour")
p7 + theme_classic()
p7 #Palette graph with percentage values
p7 +
geom_bar(position = "fill", stat="identity") +
scale_y_continuous(labels = scales::percent_format())
但是,这仍然不会将条形图的总和返回为 100%。
【问题讨论】: