试图制作一个具有统一列宽的条形图,将每个 "User Experience Framework" 的计数绘制成 "Customer Journey" 的分组?

Trying to make a bar chart with uniform column widths that plots the count of each "User Experience Framework" into groupings of "Customer Journey"?

目标是根据以下数据制作条形图。数据应按用户体验框架聚集到每个客户旅程区域。例如,“浏览”旅程区域应该为每个用户体验框架计数设置一个单独的栏。例如,浏览 = 执行 (5),系统 (3)。 这变得棘手的是,我们希望在中间有 0,“正命中”在右边,“负命中”在左边。所有条形的大小应统一。

我不能完全做到这一点。下面是我的头像(df):

> head(df,30)
          Journey.Area Experience.Framework Postive.or.Negative
1           Installing     People/Associate                   1
2        Using Product            Execution                  -1
3           Installing     People/Associate                   1
4             Delivery            Execution                  -1
5           Installing     People/Associate                  -1
6             Delivery     People/Associate                   1
7           Installing            Execution                  -1
8        Using Product            Execution                  -1
9             Browsing     People/Associate                  -1
10            Browsing     People/Associate                  -1
11            Browsing     People/Associate                   1
12              Buying              Systems                  -1
13            Delivery            Execution                  -1
14            Delivery     People/Associate                   1
15          Installing            Execution                  -1
16 Deciding How to Buy       Process/Policy                   1
17          Installing     People/Associate                  -1
18          Installing     People/Associate                   1
19            Delivery            Execution                  -1
20              Buying       Process/Policy                   1
21            Delivery            Execution                  -1
22          Installing            Execution                   1
23            Browsing     People/Associate                   1
24          Installing            Execution                  -1
25            Delivery            Execution                  -1
26          Installing            Execution                  -1
27          Installing            Execution                  -1
28 Deciding How to Buy       Process/Policy                  -1
29          Installing            Execution                  -1
30            Browsing              Systems                  -1

这是我的输出(df):

> dput(df)
structure(list(Journey.Area = c("Installing", "Using Product", 
"Installing", "Delivery", "Installing", "Delivery", "Installing", 
"Using Product", "Browsing", "Browsing", "Browsing", "Buying", 
"Delivery", "Delivery", "Installing", "Deciding How to Buy", 
"Installing", "Installing", "Delivery", "Buying", "Delivery", 
"Installing", "Browsing", "Installing", "Delivery", "Installing", 
"Installing", "Deciding How to Buy", "Installing", "Browsing", 
"Delivery", "Installing", "Browsing", "Installing", "Browsing", 
"Deciding How to Buy", "Installing", "Anticipating", "Delivery", 
"Delivery", "Deciding How to Buy", "Installing", "Using Product", 
"Installing", "Delivery", "Installing", "Installing", "Deciding How to Buy", 
"Delivery", "Delivery", "Delivery", "Browsing", "Using Product", 
"Deciding How to Buy", "Delivery", "Installing", "Installing", 
"Deciding How to Buy", "Installing", "Installing", "Anticipating", 
"Installing", "Deciding How to Buy", "Deciding How to Buy", "Installing", 
"Browsing", "Delivery", "Pickup", "Anticipating", "Deciding How to Buy", 
"Using Product", "Installing", "Anticipating", "Deciding How to Buy", 
"Browsing", "Deciding How to Buy", "Buying", "Delivery", "Installing", 
"Installing", "Installing", "Deciding How to Buy", "Anticipating", 
"Delivery", "Installing", "Anticipating", "Delivery", "Delivery", 
"Delivery", "Anticipating", "Browsing", "Deciding How to Buy", 
"Deciding How to Buy", "Anticipating", "Deciding How to Buy", 
"Delivery", "Delivery", "Deciding How to Buy", "Deciding How to Buy", 
"Deciding How to Buy"), Experience.Framework = c("People/Associate", 
"Execution", "People/Associate", "Execution", "People/Associate", 
"People/Associate", "Execution", "Execution", "People/Associate", 
"People/Associate", "People/Associate", "Systems", "Execution", 
"People/Associate", "Execution", "Process/Policy", "People/Associate", 
"People/Associate", "Execution", "Process/Policy", "Execution", 
"Execution", "People/Associate", "Execution", "Execution", "Execution", 
"Execution", "Process/Policy", "Execution", "Systems", "Execution", 
"Execution", "People/Associate", "Execution", "Execution", "Process/Policy", 
"Execution", "Systems", "Execution", "Process/Policy", "Process/Policy", 
"Execution", "Execution", "Execution", "Execution", "People/Associate", 
"Execution", "Execution", "Execution", "Execution", "Execution", 
"People/Associate", "Execution", "Process/Policy", "Execution", 
"People/Associate", "People/Associate", "People/Associate", "Execution", 
"People/Associate", "Process/Policy", "Execution", "Execution", 
"Execution", "Execution", "Systems", "Execution", "Execution", 
"Execution", "Systems", "Execution", "People/Associate", "Execution", 
"Execution", "People/Associate", "People/Associate", "Systems", 
"Execution", "Execution", "People/Associate", "Execution", "People/Associate", 
"Systems", "Execution", "Execution", "Execution", "Execution", 
"Execution", "Execution", "Execution", "Execution", "People/Associate", 
"People/Associate", "Execution", "Systems", "Execution", "Execution", 
"People/Associate", "People/Associate", "Execution"), Postive.or.Negative = c(1L, 
-1L, 1L, -1L, -1L, 1L, -1L, -1L, -1L, -1L, 1L, -1L, -1L, 1L, 
-1L, 1L, -1L, 1L, -1L, 1L, -1L, 1L, 1L, -1L, -1L, -1L, -1L, -1L, 
-1L, -1L, -1L, -1L, 1L, -1L, 1L, -1L, -1L, -1L, -1L, 1L, 1L, 
-1L, -1L, -1L, 1L, -1L, -1L, 1L, -1L, -1L, -1L, -1L, -1L, -1L, 
-1L, 1L, 1L, 1L, -1L, 1L, -1L, -1L, 1L, 1L, -1L, -1L, -1L, -1L, 
-1L, -1L, 1L, 1L, -1L, 1L, -1L, -1L, -1L, 1L, -1L, -1L, 1L, -1L, 
-1L, -1L, -1L, -1L, -1L, 1L, -1L, -1L, -1L, 1L, -1L, -1L, 1L, 
-1L, -1L, 1L, 1L, 1L)), class = "data.frame", row.names = c(NA, 
-100L))

同样,图中所有列的宽度都应相同。负数应该向左,正数应该向右。附件是一张接近的照片...但您会注意到条形的宽度不同。

我想你可能想要 geom_col(position = position_dodge2(preserve = "single"))

编辑:

您可以先计算数据以获得每个类别的单个条:

library(tidyverse)
df %>%
  count(Journey.Area, Experience.Framework, 
        wt = Postive.or.Negative, name = "Positive.or.Negative") %>%
  ggplot(aes(Positive.or.Negative, Journey.Area, fill = Experience.Framework)) +
  geom_col(position = position_dodge2(preserve = "single"))


比较:

data.frame(Journey.Area = c("Installing", rep("Using Product", 3)),
           Experience.Framework = c("A","A","B","C"),
           Positive.or.Negative = c(-5, 4:6)) %>%
  ggplot(aes(Positive.or.Negative, Journey.Area, fill = Experience.Framework)) +
  geom_col(position = "dodge")                               # (1)
  geom_col(position = position_dodge())                      # (1)
  geom_col(position = position_dodge2())                     # (2)
  geom_col(position = position_dodge2(preserve = "single"))  # (3)

(1)

(2)

(3)