R:如何在单张图中绘制两列比较直方图?

问题描述 投票:0回答:1

R:如何在单个图中绘制两列比较直方图?

DataSet like:

Promise Bin             Due Bin

early                   early             
early                   >50
early                   >50
>50                     >50
>50                     >50
<=50                    <=50
early                   early
early                   early
<=5                     <50
<=5                     <=5
<=30                    <=30
early                   early
<=30                    >50
<=30                    <=30                    
<=10                    <=10

预期地块:enter image description here

r ggplot2 plot charts plotly
1个回答
0
投票

您可以执行以下操作:

df %>% pivot_longer(everything(),names_to = "var",values_to = "val") %>% 
  group_by(var,val) %>% count() %>%
  ggplot(aes(x = val, y = n, fill = var))+
  geom_col(position = position_dodge())

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.