我的数据表如下所示:
table_name expected_value observed_value
<chr> <dbl> <dbl>
1 table1 95237608 95100229
2 table2 3014052 3014052
3 table3 3024749 3024749
我想创建一个多变量条形图来比较每个表的expected_value
和observed_value
。
看起来像这样:
首先在 ggplot 中这样做,您必须将格式从宽更改为长 (tidyr::gather),然后映射美学(选择要映射的变量),最后您必须使用 stat “identity” 而不是默认的“数数”,
library(ggplot2)
library(tidyr)
library(dplyr)
df <- data.frame(table_name =c("a", "b","c"), expected=runif(3), observed=runif(3))
gather(df, key, value, -table_name) %>% ggplot(aes(table_name, value, fill=key)) + geom_bar(stat="identity", position="dodge")
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句