目標是根據以下資料制作條形圖。資料應通過用戶體驗框架聚集到每個客戶旅程區域。例如,“瀏覽”旅程區域應該為每個用戶體驗框架計數有一個單獨的欄。例如,瀏覽 = 執行 (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))
同樣,在圖中所有列的寬度都應該相同。負數應向左,正數應向右。附件是一張接近的照片……但您會注意到這些條的寬度不同。

uj5u.com熱心網友回復:
我想你可能想要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)

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/477210.html
