简体   繁体   中英

Plot a multivariate histogram in R

I would like to plot 6 different variables with their corresponding calculated statistical data. 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?

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")

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM