I have a dataframe like this:
library(tidyverse)
data <- tibble(Question_num = rep(c("Question_1", "Question_2"),each= 5),
Answer = rep(c('Strongly disagree',
'Disagree',
'Neutral',
'Agree',
'Strongly agree'), 2),
n = c(792, 79, 69, 46, 24, 34, 34, 111, 229, 602),
prop = c(78.4, 7.82, 6.83, 4.55, 2.38, 3.37, 3.37, 11.0, 22.7, 59.6))
where:
Question_num is the label of a question;
Answer is the response mode;
n is a simple count for each response mode;
prop is proportion, in percentage;
I would like to represent it graphically through a dynamic bar graph with divergent colours. Perhaps, this would be a starting point:
library(plotly)
library(RcolorBrewer)
data %>%
plot_ly(x = ~prop,
y = ~Question_num,
color = ~Answer) %>%
add_bars(colors = "RdYlBu") %>%
layout(barmode = "stack")
Is it possible, with Plotly in R, to obtain an ordered plot, which has the neutral category clearly delineated (in the center) and the percentages summarised by grouping the extreme categories together (even if they are in their plotted in different colours)? What I would like to obtain is a plot similar to this one:
The plot in the picture is obtained from a dataset in a different format (wide, not long) and with the likert package, which computes everything automatically. Could such a result be achieved with plotly (both for percentages and for counts)? If so, how?
I could not find any documentation to answer this challenging question.
Thank you very much to those who can help me.