假设我有一个数据框架,在这个框架中,人们对45个项目做出react ,按照利克特量表(5分)表示他们感到焦虑的"频率"和"强度".因此,该数据集由90个项目组成.

每个人都有一个数据集,我想建立一个曲线图,其中X轴是频率(数字1到5),Y轴是强度(数字1到5),每个点都是一个项目的react .

plot

我真的很难策划这件事.

数据集是

df = structure(list(type = c("f1", "i1", "f2", "i2", "f3", "i3", "f4", 
 "i4", "f5", "i5", "f6", "i6", "f7", "i7", "f8", "i8", "f9", "i9", 
 "f10", "i10", "f11", "i11", "f12", "i12", "f13", "i13", "f14", 
 "i14", "f15", "i15", "f16", "i16", "f17", "i17", "f18", "i18", 
 "f19", "i19", "f20", "i20", "f21", "i21", "f22", "i22", "f23", 
 "i23", "f24", "i24", "f25", "i25", "f26", "i26", "f27", "i27", 
 "f28", "i28", "f29", "i29", "f30", "i30", "f31", "i31", "f32", 
 "i32", "f33", "i33", "f34", "i34", "f35", "i35", "f36", "i36", 
 "f37", "i37", "f38", "i38", "f39", "i39", "f40", "i40", "f41", 
 "i41", "f42", "i42", "f43", "i43", "f44", "i44", "f45", "i45"
), item = c(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 
 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 
 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 
 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 
 33, 34, 34, 35, 35, 36, 36, 37, 37, 38, 38, 39, 39, 40, 40, 41, 
 41, 42, 42, 43, 43, 44, 44, 45, 45), value = c(1, 1, 1, 1, 2, 
 2, 1, 1, 0, 0, 0, 0, 1, 1, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
 2, 2, 0, 0, 1, 1, 2, 2, 4, 2, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 
 2, 1, 0, 1, 2, 3, 2, 0, 0, 0, 0, 0, 0, 5, 3, 1, 1, 2, 3, 3, 2, 
 2, 1, 5, 1, 2, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 
 0), type2 = c("Freq", "Int", "Freq", "Int", "Freq", "Int", "Freq", 
 "Int", "Freq", "Int", "Freq", "Int", "Freq", "Int", "Freq", "Int", 
 "Freq", "Int", "Freq", "Int", "Freq", "Int", "Freq", "Int", "Freq", 
 "Int", "Freq", "Int", "Freq", "Int", "Freq", "Int", "Freq", "Int", 
 "Freq", "Int", "Freq", "Int", "Freq", "Int", "Freq", "Int", "Freq", 
 "Int", "Freq", "Int", "Freq", "Int", "Freq", "Int", "Freq", "Int", 
 "Freq", "Int", "Freq", "Int", "Freq", "Int", "Freq", "Int", "Freq", 
 "Int", "Freq", "Int", "Freq", "Int", "Freq", "Int", "Freq", "Int", 
 "Freq", "Int", "Freq", "Int", "Freq", "Int", "Freq", "Int", "Freq", 
 "Int", "Freq", "Int", "Freq", "Int", "Freq", "Int", "Freq", "Int", 
 "Freq", "Int")), row.names = c(NA, -90L), class = c("tbl_df", 
 "tbl", "data.frame"))

剧情是

ggplot(df, aes(x = type2, y = value)) +
  geom_jitter() +
  scale_x_discrete(name ="Freq", 
                   limits=c("1","2","3","4","5")) +
  scale_y_discrete(name ="Inten", 
                   limits=c("1","2","3","4","5"))

推荐答案

看起来我们可以go 掉type列,并使用item列作为关键字来组织相应的观察.Ggplot2最容易处理"整齐"的数据,出于这个目的,它将是每个观察到的人-强度组合,这本身就有一个频率.为此,我们可以使用tidyr::pivot_wider将每对IntFreq的观测值转换为同一行中的两列.然后,我们可以将Int列映射到x,将Freq列映射到y.

library(tidyverse)
df |>
  select(-type) |> 
  pivot_wider(names_from = type2, values_from = value) |>
  ggplot(aes(Freq, Int)) +
  geom_jitter(width = 0.2, height = 0.2) +
  scale_x_discrete(name ="Freq", 
                   limits=c("1","2","3","4","5")) +
  scale_y_discrete(name ="Inten", 
                   limits=c("1","2","3","4","5"))

enter image description here

R相关问答推荐

如何将y轴上的线定位得彼此更近

将带有范围的字符串转换为R中的数字载体

如何从其他前面列中减go 特定列的平均值?

将模拟变量乘以多个观测结果中的模拟变量

使用ggplot 2根据R中的类别排列Likert比例gplot

更改Heatmap Annotation对象的名称

如何得到每四个元素向量R?

将. xlsx内容显示为HTML表

LOF中的插图短文字幕

使用带有OR条件的grepl过滤字符串

仅 Select 超过9行的CSV文件

根据纬度和距离连接两个数据集

R -如何分配夜间GPS数据(即跨越午夜的数据)相同的开始日期?

提高圣彼得堡模拟的速度

如何计算每12行的平均数?

在不对R中的变量分组的情况下取两行的平均值

R基于变量组合创建新的指标列

抽样变换-REXP与RWEIBUR

我已经运行了几个月的代码的`Palette()`中出现了新的gglot错误

从矩阵创建系数图