I'm trying to split my graph so into /- on the x axis... meaning show negatives to the left of zero and positive comments to the right. Right now, they are all lumped together. When we do this it's important that the "count of occurrences" is still reflected like in the original graph.
Here is my head(df)
> head(df)
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
Here is my put(head(df))
> dput(head(df))
structure(list(Journey.Area = c("Installing", "Using Product",
"Installing", "Delivery", "Installing", "Delivery"), Experience.Framework = c("People/Associate",
"Execution", "People/Associate", "Execution", "People/Associate",
"People/Associate"), Postive.or.Negative = c(1L, -1L, 1L, -1L,
-1L, 1L)), row.names = c(NA, 6L), class = "data.frame")
Here is my code for the current graph. How do I change it so that it graphs the Positive.or.Negative one direction of zero or the other as applicable:
library(ggplot2)
library(dplyr)
df %>%
mutate(Journey.Area = factor(Journey.Area,
levels = c("Getting Assistance", "Returning", "Using Product", "Installing",
"Delivery", "Pickup", "Anticipating", "Buying",
"Deciding How to Buy", "Browsing"))) %>%
count(Journey.Area,Experience.Framework) %>%
ggplot(aes(Journey.Area,n,fill=Experience.Framework))
geom_col(position = "dodge")
coord_flip()
labs(fill="", x="Customer Journey Area", y="User Experience Framework")
theme(legend.position = "bottom") ggtitle("Customer Sentiment Matrix")
theme(plot.title = element_text(hjust = 0.5))
CodePudding user response:
First I removed your count
command and change the geom_col
to geom_bar
where I added stat="identity"
. You can use the following code:
library(ggplot2)
library(dplyr)
df %>%
mutate(Journey.Area = factor(Journey.Area,
levels = c("Getting Assistance", "Returning", "Using Product", "Installing",
"Delivery", "Pickup", "Anticipating", "Buying",
"Deciding How to Buy", "Browsing"))) %>%
ggplot(aes(Journey.Area,Postive.or.Negative,fill=Experience.Framework))
geom_bar(position = "dodge", stat = "identity")
coord_flip()
labs(fill="", x="Customer Journey Area", y="User Experience Framework")
theme(legend.position = "bottom") ggtitle("Customer Sentiment Matrix")
theme(plot.title = element_text(hjust = 0.5))
Output:
CodePudding user response:
Perhaps something like this will work for you?
df %>%
group_by_all() %>%
summarise(score = n() * Postive.or.Negative) %>%
ggplot(aes(x = score, y = Journey.Area, fill = Experience.Framework))
geom_col(position = position_dodge(), width = 0.5)
geom_vline(xintercept = 0)
theme_light(base_size = 16)
scale_x_continuous(limits = c(-2, 2), labels = abs)
scale_fill_brewer(palette = 'Set1')
labs(x = 'Negative Comments Positive Comments')