李克特图 - 年龄为 y 轴,响应为 x 轴

Likert Plot - Age as y axis, response as x axis

提问人:TGuillemin 提问时间:11/17/2023 最后编辑:jay.sfTGuillemin 更新时间:11/19/2023 访问量:25

问:

enter image description here我对渔民进行了调查,以了解他们的捕鱼偏好,并正在分析R中的数据。

我想制作李克特图,但将它们分为“钓鱼年”类别(见图)。IE 具有通常的李克特图布局,但 y 轴上的因子是不同的钓鱼时间量(“0-5”、“6-10”、“11-15”、“16-20”、“21-25”、“26-30”、“31-35”、“36-40”、“40+”)

例如:

我的一个问题是,“你最常钓鱼的船的平均尺寸有什么变化吗?

可能的响应是:

  1. 平均而言,我用比以前更小的船捕鱼
  2. 平均而言,我钓鱼的船只的大小没有变化
  3. 平均而言,我从比以前更大的船上捕鱼

我还有一个专栏,询问垂钓者他们钓鱼了多少年,数值从 1 到 50 不等。

我正在使用 likert 包并设法在 y 轴上制作没有年份的绘图,但我真的很难以一种我可以创建按年级组细分的绘图的方式布局数据。

如果有人知道如何做到这一点,请告诉我。

我使用以下代码成功制作了李克特图:

likert_data <-  select(interview_data, starts_with("Q5."))
likert_data <- likert_data %>%
  mutate(across(everything(), as.factor))
likert_obj <- likert(likert_data)
plot(likert_obj)
R 数据库 李克特

评论


答:

0赞 jay.sf 11/19/2023 #1

这很容易使用。创建一个 first.barplottableproportions

> (dat_tb <- with(dat, table(y_fish_cat, any_change)) |> proportions(margin=1))
          any_change
y_fish_cat   smaller no change    bigger
     0-5   0.1428571 0.5714286 0.2857143
     6-10  0.3750000 0.3750000 0.2500000
     11-15 0.0000000 0.5000000 0.5000000
     16-20 0.1250000 0.5000000 0.3750000
     21-25 0.5000000 0.2500000 0.2500000
     26-30 0.4000000 0.5000000 0.1000000
     31-35 0.1428571 0.7142857 0.1428571
     36-40 0.3888889 0.3333333 0.2777778
     40+   0.4761905 0.3333333 0.1904762
> b <- barplot(t(dat_tb), beside=FALSE, horiz=TRUE, col=c(4, 8, 2), las=1)
> xm <- dat_tb/2 + cbind(0, matrixStats::rowCumsums(dat_tb[, -3]))
> text(replace(xm, xm == 0, NA), b, labels=sprintf('%s%%', round(dat_tb*100, 1)))

enter image description here


数据:

n <- 100
set.seed(42)
dat <- data.frame(
  y_fishing=sample.int(50, n, replace=TRUE),
  any_change=factor(sample(c('smaller', 'no change', 'bigger'), n, replace=TRUE),
                    levels=c('smaller', 'no change', 'bigger'))
)
dat <- transform(dat,
                 y_fish_cat=cut(y_fishing, c(seq(0, 40, 5), Inf),
                                labels=c("0-5", "6-10", "11-15", "16-20", 
                                         "21-25", "26-30", "31-35", "36-40", 
                                         "40+")))