将两个列表合并为两个级别

时间:2015-11-01 23:17:20

标签: r plot factors

我有两个列表:

t1.visit.attendance [1] 77 74 71 62 59 56 55

t2.visit.attendance [1] 37 34 33 31 27 26 24

我想做一个因素,水平是t1.visit.attendance和t2.visit.attendance。请注意:t1和t2是两种不同的治疗类型。

然后我想在同一个图上对数字1到7(对应于第n次访问)绘制数据的散点图,其中每种处理类型都是彩色编码的。

2 个答案:

答案 0 :(得分:3)

格子库有一个名为make.groups的辅助函数。例如

t1.visit.attendance<-c(77,74,71,62,59,56,55)
t2.visit.attendance<-c(37,34,33,31,27,26,24)

lattice::make.groups(t1=t1.visit.attendance, t2=t2.visit.attendance)
#     data which
# t11   77    t1
# t12   74    t1
# t13   71    t1
# t14   62    t1
# ...
# t26   26    t2
# t27   24    t2

答案 1 :(得分:0)

另一种方式,只是为了显示一些选项,涉及t1.visit.attendance <- c(77,74,71,62,59,56,55) t2.visit.attendance <- c(37,34,33,31,27,26,24) df <- data.frame(t1 = t1.visit.attendance, t2 = t2.visit.attendance) newdf <- melt(df, measure.vars = c("t1", "t2"), variable.name = "visits") > newdf visits value 1 t1 77 2 t1 74 3 t1 71 4 t1 62 5 t1 59 6 t1 56 7 t1 55 8 t2 37 9 t2 34 10 t2 33 11 t2 31 12 t2 27 13 t2 26 14 t2 24 函数:

dotplot

要显示除散点图以外的情节,以下是使用ggplot(newdf) + aes(x=value, color = visits) + geom_dotplot() + theme(axis.text.y=element_blank())

的另一种方式
{{1}}

产生

Dotplot of visits categorized by treatment type

相关问题