[英]Plot a multivariate histogram in R
I would like to plot 6 different variables with their corresponding calculated statistical data. 我想绘制6个不同的变量及其对应的计算统计数据。 The following dataframe may serve as an example 以下数据框可以作为示例
X aggr_a aggr_b count
<chr> <dbl> <dbl> <dbl>
1 A 470676 594423 58615
2 B 549142 657291 67912
3 C 256204 311723 26606
4 D 248256 276593 40201
5 E 1581770 1717788 250553
6 F 1932096 2436769 385556
I would like to plot each row as category with its statistics as histogram bins. 我想将每一行都绘制为类别,并将其统计信息绘制为直方图箱。 The desired output is 所需的输出是
May I use ggplots for this kind of graphs? 我可以将ggplots用于此类图形吗?
All the available resources seem to cover the uni variate case only. 所有可用资源似乎仅涵盖单变量情况。
library(tidyverse)
df = read.table(text = "
X aggr_a aggr_b count
A 470676 594423 58615
B 549142 657291 67912
C 256204 311723 26606
D 248256 276593 40201
E 1581770 1717788 250553
F 1932096 2436769 385556
", header=T)
df %>%
gather(type,value,-X) %>% # reshape dataset
ggplot(aes(X,value,fill=type))+
geom_bar(position = "dodge", stat = "identity")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.