You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Grouped likert scale using Likert package in R, results in plot with reversed scale. I have a series of likert variables (strongly disagree-strongly agree) and a grouping variable from a survey. I am using Likert package in R and everything goes well until I want to plot one of those likert variables grouped by a grouping variable in a 100% stacked bars plot. In likert package to plot 100% stacked bar you can use the option centered=FALSE. This option works fine when plotting without grouping.
In the following code you can see the problem arising in the 'L3' plot, in that the bars are inverted on the x axis compared to 'L2'. The blue color should be on the right and the yellows on the left. Note also that the percentages for neutral are not aligned, but they would be aligned if the bars were in the correct sense
`library(likert)
library(tidyverse)
n <- 3000
set.seed(123)
Dataframe where Q1a,b,c are the likert variables with levels 1,2,3,4,5 and 3 is the centre (neutral answer)
some_made_up_data <- data.frame(
Q1a = as.factor(sample(c(1,2,3,4,5), n, replace = TRUE, prob = c(.03,.07,.2,.4, .3))),
Q1b = as.factor(sample(c(1,2,3,4,5), n, replace = TRUE, prob = c(.02,.1,.2,.3, .3))),
Q1c = as.factor(sample(c(1,2,3,4,5), n, replace = TRUE, prob = c(.05,.2,.2,.4, .2))),
group = as.factor(sample(c("g1", "g2", "g3", "g4", "g5"), n, replace = TRUE))
)
Grouped likert scale using Likert package in R, results in plot with reversed scale. I have a series of likert variables (strongly disagree-strongly agree) and a grouping variable from a survey. I am using Likert package in R and everything goes well until I want to plot one of those likert variables grouped by a grouping variable in a 100% stacked bars plot. In likert package to plot 100% stacked bar you can use the option centered=FALSE. This option works fine when plotting without grouping.
In the following code you can see the problem arising in the 'L3' plot, in that the bars are inverted on the x axis compared to 'L2'. The blue color should be on the right and the yellows on the left. Note also that the percentages for neutral are not aligned, but they would be aligned if the bars were in the correct sense
`library(likert)
library(tidyverse)
n <- 3000
set.seed(123)
Dataframe where Q1a,b,c are the likert variables with levels 1,2,3,4,5 and 3 is the centre (neutral answer)
some_made_up_data <- data.frame(
Q1a = as.factor(sample(c(1,2,3,4,5), n, replace = TRUE, prob = c(.03,.07,.2,.4, .3))),
Q1b = as.factor(sample(c(1,2,3,4,5), n, replace = TRUE, prob = c(.02,.1,.2,.3, .3))),
Q1c = as.factor(sample(c(1,2,3,4,5), n, replace = TRUE, prob = c(.05,.2,.2,.4, .2))),
group = as.factor(sample(c("g1", "g2", "g3", "g4", "g5"), n, replace = TRUE))
)
Simple Plot 100% stacked bars
L1<-likert(some_made_up_data[,-4]) %>%
plot(type="bar",
centered=F
)
Plot with grouping, standard divergent bars
L2<-likert(some_made_up_data[,1,drop=FALSE],grouping = some_made_up_data$group) %>%
plot(type="bar",
centered=T
)
Plot with grouping, 100% stacked bars
Here I am subsetting the dataframe to use only the first of the likert variables and compare distribution s across groups
L3<-likert(some_made_up_data[,1,drop=FALSE],grouping = some_made_up_data$group) %>%
plot(type="bar",
centered=F
)
View plots
L1
L2
L3`
The text was updated successfully, but these errors were encountered: