我正在使用调查数据,并且我有一个大型矩阵(该矩阵我称为sleepAct),具有144行和1列。睡眠矩阵中填充了O(未执行活动)和1(已执行活动)
Below dput(head(sleepAct, 20))
structure(c(90, 89, 89, 89, 88, 86, 85, 86, 85, 85, 84, 81, 76,
74, 69, 61, 62, 54, 50, 46), .Dim = c(20L, 1L), .Dimnames = list(
c("04:00", "04:10", "04:20", "04:30", "04:40", "04:50", "05:00",
"05:10", "05:20", "05:30", "05:40", "05:50", "06:00", "06:10",
"06:20", "06:30", "06:40", "06:50", "07:00", "07:10"), NULL))
使用下面的代码,我将该矩阵绘制为:
sleep<-0 #created an object sleep
sleep<-ifelse(ActivityMatrix[,39:182]>109 & ActivityMatrix[,39:182]< 121, 1, sleep) ### see ActivityMatrix (dim row=93 col=182)is the matrix from which I extract sleep.
sleepAct<-colSums(sleep[,]) ##summed up the 0's and 1's from sleep matrix
sleepAct<-as.matrix(sleepAct) ##defined sleepAct matrix
rownames(sleepAct) <- c("04:00", "04:10","04:20", "04:30", "04:40", "04:50", "05:00", "05:10", "05:20", "05:30", "05:40", "05:50",
"06:00", "06:10", "06:20", "06:30", "06:40", "06:50",
"07:00", "07:10", "07:20", "07:30", "07:40", "07:50",
"08:00", "08:10", "08:20", "08:30", "08:40", "08:50",
"09:00", "09:10", "09:20", "09:30", "09:40", "09:50",
"10:00", "10:10", "10:20", "10:30", "10:40", "10:50",
"11:00", "11:10", "11:20", "11:30", "11:40", "11:50",
"12:00", "12:10", "12:20", "12:30", "12:40", "12:50",
"13:00", "13:10", "13:20", "13:30", "13:40", "13:50",
"14:00", "14:10", "14:20", "14:30", "14:40", "14:50",
"15:00", "15:10", "15:20", "15:30", "15:40", "15:50",
"16:00", "16:10", "16:20", "16:30", "16:40", "16:50",
"17:00", "17:10", "17:20", "17:30", "17:40", "17:50",
"18:00", "18:10", "18:20", "18:30", "18:40", "18:50",
"19:00", "19:10", "19:20", "19:30", "19:40", "19:50",
"20:00", "20:10", "20:20", "20:30", "20:40", "20:50",
"21:00", "21:10", "21:20", "21:30", "21:40", "21:50",
"22:00", "22:10", "22:20", "22:30", "22:40", "22:50",
"23:00", "23:10", "23:20", "23:30", "23:40", "23:50",
"00:00", "00:10", "00:20", "00:30", "00:40", "00:50",
"01:00", "01:10", "01:20", "01:30", "01:40", "01:50",
"02:00", "02:10", "02:20", "02:30", "02:40", "02:50",
"03:00", "03:10", "03:20", "03:30" ,"03:40", "03:50")
plot(sleepAct, type = "o", col="red", xlab="Time", ylab = "Number of sleep activities",
main="Individual diaries:Activities related to sleep (Activity codes: 110, 111, 120)",axes=FALSE, xlim=c(1,144), ylim=c(0,100), pos=0)
axis(1, at=1:144, labels=rownames(sleepAct), by=10, pos=0)
axis(2, at=c(0,100), labels=c("",""), pos=1)
axis(2, at=seq(0, 100, by=10),lwd.ticks=1, las=1, pos=1, cex=0.3)
rect(xleft=96,xright =73,ybottom=range(sleepAct[1],ytop=range(sleepAct)[2], density=10, col = "blue")
#
我从中提取sleep和sleepAct矩阵的初始ActivityMatrix结构
dput (head(ActivityMatrix ,3))
structure(list(id = c(546, 828, 61), daynum = structure(c(2,
2, 2), label = "Diary number", class = c("labelled", "numeric"
)), serial = c(14280413, 16210713, 11090318), pnum = c(2, 1,
2), ind_wt = c(1.50173440984951, 0.534998962731057, NA), WorkSta = structure(c(2,
2, 2), label = "Economic activity status", class = c("labelled",
"numeric")), NumAdult = structure(c(2, 3, 2), label = "Number of adults in household", class = c("labelled",
"numeric")), NumChild = structure(c(3, 1, 1), label = "Number of children in household", class = c("labelled",
"numeric")), MarStat = structure(c(3, 3, 3), label = "Marital status", class = c("labelled",
"numeric")), Wages = structure(c(1, 1, 1), label = "Sources of income household has at present: Wages/salary", class = c("labelled",
"numeric")), SelfEmp = structure(c(2, 2, 1), label = "Sources of income household has at present: Income from self-employment or farmi", class = c("labelled",
"numeric")), Pension = structure(c(2, 2, 2), label = "Sources of income household has at present: Pensions", class = c("labelled",
"numeric")), UnempBen = structure(c(2, 2, 2), label = "Sources of income household has at present: Unemployment benefit", class = c("labelled",
"numeric")), BenOth = structure(c(2, 1, 2), label = "Sources of income household has at present: Other types of social benefits and g", class = c("labelled",
"numeric")), Invest = structure(c(2, 2, 1), label = "Sources of income household has at present: Income from investment, savings or p", class = c("labelled",
"numeric")), IncOth = structure(c(2, 2, 2), label = "Sources of income household has at present: Income from other sources", class = c("labelled",
"numeric")), Income = structure(c(-8, 4000, 3000), label = "Total monthly household income, including pensions, tax credits", class = c("labelled",
"numeric")), Wrking = structure(c(1, 1, -1), label = "Whether did any paid work in 7 days ending last Sunday", class = c("labelled",
"numeric")), FtPtWk = structure(c(1, 1, -1), label = "Whether working full or part time at main job", class = c("labelled",
"numeric")), JbPerm = structure(c(1, 1, -1), label = "Whether main job is permanent, or in some way NOT permanent", class = c("labelled",
"numeric")), JbNtPerm = structure(c(-1, -1, -1), label = "Way in which job NOT permanent", class = c("labelled",
"numeric")), HrWkUS = structure(c(40, 37, -1), label = "Number of hours per week usually worked in main job", class = c("labelled",
"numeric")), HrWkAc = structure(c(45, 40, -1), label = "Number of hours last week actually worked in main job", class = c("labelled",
"numeric")), ShiftWk = structure(c(3, 3, -1), label = "Whether do shiftwork in (main) job", class = c("labelled",
"numeric")), ShiftPat = structure(c(-1, -1, -1), label = "Type of shift pattern worked", class = c("labelled",
"numeric")), WkArrang = structure(c(0, 0, -1), label = "Special working arrangements: Flexible hours, with specified core hours", class = c("labelled",
"numeric")), WkArran2 = structure(c(0, 0, -1), label = "Special working arrangements: Flexible hours, with no specified core hours", class = c("labelled",
"numeric")), WkArran3 = structure(c(0, 0, -1), label = "Special working arrangements: Annualised hours contract", class = c("labelled",
"numeric")), WkArran4 = structure(c(0, 0, -1), label = "Special working arrangements: Term time working", class = c("labelled",
"numeric")), WkArran5 = structure(c(0, 0, -1), label = "Special working arrangements: Job sharing", class = c("labelled",
"numeric")), WkArran6 = structure(c(0, 0, -1), label = "Special working arrangements: A nine-day fortnight", class = c("labelled",
"numeric")), WkArran7 = structure(c(0, 0, -1), label = "Special working arrangements: A four-and-a-half day week", class = c("labelled",
"numeric")), WkArran8 = structure(c(0, 0, -1), label = "Special working arrangements: Zero hours contract", class = c("labelled",
"numeric")), WkArran9 = structure(c(1, 1, -1), label = "Special working arrangements: None of these", class = c("labelled",
"numeric")), WrkLoc = structure(c(2, 2, -1), label = "Whether, in main job, work mainly", class = c("labelled",
"numeric")), DiaryDay_Act = structure(c(2, 2, 2), label = "Diary Day - ACTUAL DAY", class = c("labelled",
"numeric")), dia_wt_a = c(1.96119606494904, 0.567432880401611,
1.87476718425751), dia_wt_b = c(1.3142769635514, 0.41010069443133,
1.26491230490937), act1_1 = structure(c(110, 110, 110), label = "Primary activity: 04:00-04:10", class = c("labelled",
"numeric")), act1_2 = structure(c(110, 110, 110), label = "Primary activity: 04:10-04:20", class = c("labelled",
"numeric")), act1_3 = structure(c(110, 110, 110), label = "Primary activity: 04:20-04:30", class = c("labelled",
"numeric")), act1_4 = structure(c(110, 111, 110), label = "Primary activity: 04:30-04:40", class = c("labelled",
"numeric")), act1_5 = structure(c(110, 111, 110), label = "Primary activity: 04:40-04:50", class = c("labelled",
"numeric")), act1_6 = structure(c(110, 111, 110), label = "Primary activity: 04:50-05:00", class = c("labelled",
"numeric")), act1_7 = structure(c(110, 111, 110), label = "Primary activity: 05:00-05:10", class = c("labelled",
"numeric")), act1_8 = structure(c(110, 111, 110), label = "Primary activity: 05:10-05:20", class = c("labelled",
"numeric")), act1_9 = structure(c(110, 111, 110), label = "Primary activity: 05:20-05:30", class = c("labelled",
"numeric")), act1_10 = structure(c(110, 111, 110), label = "Primary activity: 05:30-05:40", class = c("labelled",
"numeric")), act1_11 = structure(c(110, 111, 110), label = "Primary activity: 05:40-05:50", class = c("labelled",
"numeric")), act1_12 = structure(c(110, 111, 110), label = "Primary activity: 05:50-06:00", class = c("labelled",
"numeric")), act1_13 = structure(c(110, 111, 110), label = "Primary activity: 06:00-06:10", class = c("labelled",
"numeric")), act1_14 = structure(c(110, 111, 110), label = "Primary activity: 06:10-06:20", class = c("labelled",
"numeric")), act1_15 = structure(c(110, 111, 110), label = "Primary activity: 06:20-06:30", class = c("labelled",
"numeric")), act1_16 = structure(c(310, 111, 110), label = "Primary activity: 06:30-06:40", class = c("labelled",
"numeric")), act1_17 = structure(c(310, 111, 110), label = "Primary activity: 06:40-06:50", class = c("labelled",
"numeric")), act1_18 = structure(c(310, 111, 110), label = "Primary activity: 06:50-07:00", class = c("labelled",
"numeric")), act1_19 = structure(c(9120, 111, 110), label = "Primary activity: 07:00-07:10", class = c("labelled",
"numeric")), act1_20 = structure(c(9120, 111, 110), label = "Primary activity: 07:10-07:20", class = c("labelled",
"numeric")), act1_21 = structure(c(9120, 3110, 110), label = "Primary activity: 07:20-07:30", class = c("labelled",
"numeric")), act1_22 = structure(c(9120, 210, 110), label = "Primary activity: 07:30-07:40", class = c("labelled",
"numeric")), act1_23 = structure(c(9120, 310, 110), label = "Primary activity: 07:40-07:50", class = c("labelled",
"numeric")), act1_24 = structure(c(9120, 3290, 110), label = "Primary activity: 07:50-08:00", class = c("labelled",
"numeric")), act1_25 = structure(c(9120, 8210, 110), label = "Primary activity: 08:00-08:10", class = c("labelled",
"numeric")), act1_26 = structure(c(210, 8210, 110), label = "Primary activity: 08:10-08:20", class = c("labelled",
"numeric")), act1_27 = structure(c(1110, 9940, 110), label = "Primary activity: 08:20-08:30", class = c("labelled",
"numeric")), act1_28 = structure(c(1110, 9940, 110), label = "Primary activity: 08:30-08:40", class = c("labelled",
"numeric")), act1_29 = structure(c(1110, 3290, 110), label = "Primary activity: 08:40-08:50", class = c("labelled",
"numeric")), act1_30 = structure(c(1110, 210, 110), label = "Primary activity: 08:50-09:00", class = c("labelled",
"numeric")), act1_31 = structure(c(1110, 210, 110), label = "Primary activity: 09:00-09:10", class = c("labelled",
"numeric")), act1_32 = structure(c(1110, 5310, 210), label = "Primary activity: 09:10-09:20", class = c("labelled",
"numeric")), act1_33 = structure(c(1110, 5310, 210), label = "Primary activity: 09:20-09:30", class = c("labelled",
"numeric")), act1_34 = structure(c(1110, 5310, 3110), label = "Primary activity: 09:30-09:40", class = c("labelled",
"numeric")), act1_35 = structure(c(1110, 5310, 3110), label = "Primary activity: 09:40-09:50", class = c("labelled",
"numeric")), act1_36 = structure(c(1120, 3290, 3110), label = "Primary activity: 09:50-10:00", class = c("labelled",
"numeric")), act1_37 = structure(c(1110, 5110, 3110), label = "Primary activity: 10:00-10:10", class = c("labelled",
"numeric")), act1_38 = structure(c(1110, 5110, 3110), label = "Primary activity: 10:10-10:20", class = c("labelled",
"numeric")), act1_39 = structure(c(1110, 310, 7330), label = "Primary activity: 10:20-10:30", class = c("labelled",
"numeric")), act1_40 = structure(c(1110, 3620, 7330), label = "Primary activity: 10:30-10:40", class = c("labelled",
"numeric")), act1_41 = structure(c(1110, 9360, 7330), label = "Primary activity: 10:40-10:50", class = c("labelled",
"numeric")), act1_42 = structure(c(1110, 9360, 3540), label = "Primary activity: 10:50-11:00", class = c("labelled",
"numeric")), act1_43 = structure(c(1110, 9360, 9820), label = "Primary activity: 11:00-11:10", class = c("labelled",
"numeric")), act1_44 = structure(c(1110, 9360, 9820), label = "Primary activity: 11:10-11:20", class = c("labelled",
"numeric")), act1_45 = structure(c(1110, 9360, 9820), label = "Primary activity: 11:20-11:30", class = c("labelled",
"numeric")), act1_46 = structure(c(1110, 9360, 5190), label = "Primary activity: 11:30-11:40", class = c("labelled",
"numeric")), act1_47 = structure(c(1110, 9360, 5190), label = "Primary activity: 11:40-11:50", class = c("labelled",
"numeric")), act1_48 = structure(c(1110, 9360, 5190), label = "Primary activity: 11:50-12:00", class = c("labelled",
"numeric")), act1_49 = structure(c(1110, 3610, 5190), label = "Primary activity: 12:00-12:10", class = c("labelled",
"numeric")), act1_50 = structure(c(1110, 3610, 5190), label = "Primary activity: 12:10-12:20", class = c("labelled",
"numeric")), act1_51 = structure(c(1110, 3610, 6179), label = "Primary activity: 12:20-12:30", class = c("labelled",
"numeric")), act1_52 = structure(c(1110, 3610, 6179), label = "Primary activity: 12:30-12:40", class = c("labelled",
"numeric")), act1_53 = structure(c(1110, 5291, 210), label = "Primary activity: 12:40-12:50", class = c("labelled",
"numeric")), act1_54 = structure(c(1110, 5291, 210), label = "Primary activity: 12:50-13:00", class = c("labelled",
"numeric")), act1_55 = structure(c(1110, 5291, 210), label = "Primary activity: 13:00-13:10", class = c("labelled",
"numeric")), act1_56 = structure(c(1110, 5291, 210), label = "Primary activity: 13:10-13:20", class = c("labelled",
"numeric")), act1_57 = structure(c(1110, 5291, 210), label = "Primary activity: 13:20-13:30", class = c("labelled",
"numeric")), act1_58 = structure(c(1110, 5291, 6144), label = "Primary activity: 13:30-13:40", class = c("labelled",
"numeric")), act1_59 = structure(c(1110, 5291, 6144), label = "Primary activity: 13:40-13:50", class = c("labelled",
"numeric")), act1_60 = structure(c(1110, 5190, 6144), label = "Primary activity: 13:50-14:00", class = c("labelled",
"numeric")), act1_61 = structure(c(1110, 5291, 6179), label = "Primary activity: 14:00-14:10", class = c("labelled",
"numeric")), act1_62 = structure(c(1110, 3610, 6179), label = "Primary activity: 14:10-14:20", class = c("labelled",
"numeric")), act1_63 = structure(c(1310, 3610, 6179), label = "Primary activity: 14:20-14:30", class = c("labelled",
"numeric")), act1_64 = structure(c(1310, 3610, 5310), label = "Primary activity: 14:30-14:40", class = c("labelled",
"numeric")), act1_65 = structure(c(1310, 3610, 5310), label = "Primary activity: 14:40-14:50", class = c("labelled",
"numeric")), act1_66 = structure(c(1310, 3610, 5310), label = "Primary activity: 14:50-15:00", class = c("labelled",
"numeric")), act1_67 = structure(c(1310, 9520, 5310), label = "Primary activity: 15:00-15:10", class = c("labelled",
"numeric")), act1_68 = structure(c(1310, 5291, 5310), label = "Primary activity: 15:10-15:20", class = c("labelled",
"numeric")), act1_69 = structure(c(1110, 9520, 5310), label = "Primary activity: 15:20-15:30", class = c("labelled",
"numeric")), act1_70 = structure(c(1110, 9520, 5310), label = "Primary activity: 15:30-15:40", class = c("labelled",
"numeric")), act1_71 = structure(c(1110, 9520, 5310), label = "Primary activity: 15:40-15:50", class = c("labelled",
"numeric")), act1_72 = structure(c(1110, 9520, 5310), label = "Primary activity: 15:50-16:00", class = c("labelled",
"numeric")), act1_73 = structure(c(1110, 9520, 9820), label = "Primary activity: 16:00-16:10", class = c("labelled",
"numeric")), act1_74 = structure(c(1110, 9520, 9820), label = "Primary activity: 16:10-16:20", class = c("labelled",
"numeric")), act1_75 = structure(c(1110, 9520, 9820), label = "Primary activity: 16:20-16:30", class = c("labelled",
"numeric")), act1_76 = structure(c(1110, 3290, 5310), label = "Primary activity: 16:30-16:40", class = c("labelled",
"numeric")), act1_77 = structure(c(1110, 8190, 5310), label = "Primary activity: 16:40-16:50", class = c("labelled",
"numeric")), act1_78 = structure(c(1110, 8110, 5310), label = "Primary activity: 16:50-17:00", class = c("labelled",
"numeric")), act1_79 = structure(c(1110, 8100, 5310), label = "Primary activity: 17:00-17:10", class = c("labelled",
"numeric")), act1_80 = structure(c(1110, 8100, 5310), label = "Primary activity: 17:10-17:20", class = c("labelled",
"numeric")), act1_81 = structure(c(1110, 8100, 5310), label = "Primary activity: 17:20-17:30", class = c("labelled",
"numeric")), act1_82 = structure(c(9120, 8210, 5310), label = "Primary activity: 17:30-17:40", class = c("labelled",
"numeric")), act1_83 = structure(c(9120, 8210, 5310), label = "Primary activity: 17:40-17:50", class = c("labelled",
"numeric")), act1_84 = structure(c(9120, 8210, 5310), label = "Primary activity: 17:50-18:00", class = c("labelled",
"numeric")), act1_85 = structure(c(9120, 310, 210), label = "Primary activity: 18:00-18:10", class = c("labelled",
"numeric")), act1_86 = structure(c(9120, 310, 210), label = "Primary activity: 18:10-18:20", class = c("labelled",
"numeric")), act1_87 = structure(c(9120, 8210, 210), label = "Primary activity: 18:20-18:30", class = c("labelled",
"numeric")), act1_88 = structure(c(3290, 8210, 310), label = "Primary activity: 18:30-18:40", class = c("labelled",
"numeric")), act1_89 = structure(c(310, 8210, 310), label = "Primary activity: 18:40-18:50", class = c("labelled",
"numeric")), act1_90 = structure(c(9610, 3290, 310), label = "Primary activity: 18:50-19:00", class = c("labelled",
"numeric")), act1_91 = structure(c(6160, 3611, 310), label = "Primary activity: 19:00-19:10", class = c("labelled",
"numeric")), act1_92 = structure(c(6160, 210, 9999), label = "Primary activity: 19:10-19:20", class = c("labelled",
"numeric")), act1_93 = structure(c(6160, 5310, 9999), label = "Primary activity: 19:20-19:30", class = c("labelled",
"numeric")), act1_94 = structure(c(6160, 210, 4320), label = "Primary activity: 19:30-19:40", class = c("labelled",
"numeric")), act1_95 = structure(c(6160, 210, 4320), label = "Primary activity: 19:40-19:50", class = c("labelled",
"numeric")), act1_96 = structure(c(6160, 210, 4320), label = "Primary activity: 19:50-20:00", class = c("labelled",
"numeric")), act1_97 = structure(c(6160, 210, 5120), label = "Primary activity: 20:00-20:10", class = c("labelled",
"numeric")), act1_98 = structure(c(6160, 210, 5120), label = "Primary activity: 20:10-20:20", class = c("labelled",
"numeric")), act1_99 = structure(c(6160, 210, 5120), label = "Primary activity: 20:20-20:30", class = c("labelled",
"numeric")), act1_100 = structure(c(6160, 210, 5120), label = "Primary activity: 20:30-20:40", class = c("labelled",
"numeric")), act1_101 = structure(c(6160, 210, 5120), label = "Primary activity: 20:40-20:50", class = c("labelled",
"numeric")), act1_102 = structure(c(6160, 210, 5120), label = "Primary activity: 20:50-21:00", class = c("labelled",
"numeric")), act1_103 = structure(c(9610, 9990, 5120), label = "Primary activity: 21:00-21:10", class = c("labelled",
"numeric")), act1_104 = structure(c(9610, 210, 5120), label = "Primary activity: 21:10-21:20", class = c("labelled",
"numeric")), act1_105 = structure(c(9610, 210, 5120), label = "Primary activity: 21:20-21:30", class = c("labelled",
"numeric")), act1_106 = structure(c(310, 5190, 5120), label = "Primary activity: 21:30-21:40", class = c("labelled",
"numeric")), act1_107 = structure(c(210, 5190, 5120), label = "Primary activity: 21:40-21:50", class = c("labelled",
"numeric")), act1_108 = structure(c(310, 5190, 5120), label = "Primary activity: 21:50-22:00", class = c("labelled",
"numeric")), act1_109 = structure(c(111, 5140, 310), label = "Primary activity: 22:00-22:10", class = c("labelled",
"numeric")), act1_110 = structure(c(111, 5190, 310), label = "Primary activity: 22:10-22:20", class = c("labelled",
"numeric")), act1_111 = structure(c(110, 3290, 310), label = "Primary activity: 22:20-22:30", class = c("labelled",
"numeric")), act1_112 = structure(c(110, 310, 310), label = "Primary activity: 22:30-22:40", class = c("labelled",
"numeric")), act1_113 = structure(c(110, 8120, 310), label = "Primary activity: 22:40-22:50", class = c("labelled",
"numeric")), act1_114 = structure(c(110, 8120, 310), label = "Primary activity: 22:50-23:00", class = c("labelled",
"numeric")), act1_115 = structure(c(110, 8120, 310), label = "Primary activity: 23:00-23:10", class = c("labelled",
"numeric")), act1_116 = structure(c(110, 3290, 310), label = "Primary activity: 23:10-23:20", class = c("labelled",
"numeric")), act1_117 = structure(c(110, 5310, 310), label = "Primary activity: 23:20-23:30", class = c("labelled",
"numeric")), act1_118 = structure(c(110, 110, 310), label = "Primary activity: 23:30-23:40", class = c("labelled",
"numeric")), act1_119 = structure(c(110, 110, 310), label = "Primary activity: 23:40-23:50", class = c("labelled",
"numeric")), act1_120 = structure(c(110, 110, 310), label = "Primary activity: 23:50-00:00", class = c("labelled",
"numeric")), act1_121 = structure(c(110, 110, 310), label = "Primary activity: 00:00-00:10", class = c("labelled",
"numeric")), act1_122 = structure(c(110, 110, 310), label = "Primary activity: 00:10-00:20", class = c("labelled",
"numeric")), act1_123 = structure(c(110, 110, 310), label = "Primary activity: 00:20-00:30", class = c("labelled",
"numeric")), act1_124 = structure(c(110, 110, 310), label = "Primary activity: 00:30-00:40", class = c("labelled",
"numeric")), act1_125 = structure(c(110, 110, 310), label = "Primary activity: 00:40-00:50", class = c("labelled",
"numeric")), act1_126 = structure(c(110, 110, 310), label = "Primary activity: 00:50-01:00", class = c("labelled",
"numeric")), act1_127 = structure(c(110, 110, 110), label = "Primary activity: 01:00-01:10", class = c("labelled",
"numeric")), act1_128 = structure(c(110, 110, 110), label = "Primary activity: 01:10-01:20", class = c("labelled",
"numeric")), act1_129 = structure(c(110, 110, 110), label = "Primary activity: 01:20-01:30", class = c("labelled",
"numeric")), act1_130 = structure(c(110, 110, 110), label = "Primary activity: 01:30-01:40", class = c("labelled",
"numeric")), act1_131 = structure(c(110, 110, 110), label = "Primary activity: 01:40-01:50", class = c("labelled",
"numeric")), act1_132 = structure(c(110, 110, 110), label = "Primary activity: 01:50-02:00", class = c("labelled",
"numeric")), act1_133 = structure(c(110, 110, 110), label = "Primary activity: 02:00-02:10", class = c("labelled",
"numeric")), act1_134 = structure(c(110, 110, 110), label = "Primary activity: 02:10-02:20", class = c("labelled",
"numeric")), act1_135 = structure(c(110, 110, 110), label = "Primary activity: 02:20-02:30", class = c("labelled",
"numeric")), act1_136 = structure(c(110, 110, 110), label = "Primary activity: 02:30-02:40", class = c("labelled",
"numeric")), act1_137 = structure(c(110, 110, 110), label = "Primary activity: 02:40-02:50", class = c("labelled",
"numeric")), act1_138 = structure(c(110, 110, 110), label = "Primary activity: 02:50-03:00", class = c("labelled",
"numeric")), act1_139 = structure(c(110, 110, 110), label = "Primary activity: 03:00-03:10", class = c("labelled",
"numeric")), act1_140 = structure(c(110, 110, 110), label = "Primary activity: 03:10-03:20", class = c("labelled",
"numeric")), act1_141 = structure(c(110, 110, 110), label = "Primary activity: 03:20-03:30", class = c("labelled",
"numeric")), act1_142 = structure(c(110, 110, 110), label = "Primary activity: 03:30-03:40", class = c("labelled",
"numeric")), act1_143 = structure(c(110, 110, 110), label = "Primary activity: 03:40-03:50", class = c("labelled",
"numeric")), act1_144 = structure(c(110, 110, 110), label = "Primary activity: 03:50-04:00", class = c("labelled",
"numeric"))), .Names = c("id", "daynum", "serial", "pnum", "ind_wt",
"WorkSta", "NumAdult", "NumChild", "MarStat", "Wages", "SelfEmp",
"Pension", "UnempBen", "BenOth", "Invest", "IncOth", "Income",
"Wrking", "FtPtWk", "JbPerm", "JbNtPerm", "HrWkUS", "HrWkAc",
"ShiftWk", "ShiftPat", "WkArrang", "WkArran2", "WkArran3", "WkArran4",
"WkArran5", "WkArran6", "WkArran7", "WkArran8", "WkArran9", "WrkLoc",
"DiaryDay_Act", "dia_wt_a", "dia_wt_b", "act1_1", "act1_2", "act1_3",
"act1_4", "act1_5", "act1_6", "act1_7", "act1_8", "act1_9", "act1_10",
"act1_11", "act1_12", "act1_13", "act1_14", "act1_15", "act1_16",
"act1_17", "act1_18", "act1_19", "act1_20", "act1_21", "act1_22",
"act1_23", "act1_24", "act1_25", "act1_26", "act1_27", "act1_28",
"act1_29", "act1_30", "act1_31", "act1_32", "act1_33", "act1_34",
"act1_35", "act1_36", "act1_37", "act1_38", "act1_39", "act1_40",
"act1_41", "act1_42", "act1_43", "act1_44", "act1_45", "act1_46",
"act1_47", "act1_48", "act1_49", "act1_50", "act1_51", "act1_52",
"act1_53", "act1_54", "act1_55", "act1_56", "act1_57", "act1_58",
"act1_59", "act1_60", "act1_61", "act1_62", "act1_63", "act1_64",
"act1_65", "act1_66", "act1_67", "act1_68", "act1_69", "act1_70",
"act1_71", "act1_72", "act1_73", "act1_74", "act1_75", "act1_76",
"act1_77", "act1_78", "act1_79", "act1_80", "act1_81", "act1_82",
"act1_83", "act1_84", "act1_85", "act1_86", "act1_87", "act1_88",
"act1_89", "act1_90", "act1_91", "act1_92", "act1_93", "act1_94",
"act1_95", "act1_96", "act1_97", "act1_98", "act1_99", "act1_100",
"act1_101", "act1_102", "act1_103", "act1_104", "act1_105", "act1_106",
"act1_107", "act1_108", "act1_109", "act1_110", "act1_111", "act1_112",
"act1_113", "act1_114", "act1_115", "act1_116", "act1_117", "act1_118",
"act1_119", "act1_120", "act1_121", "act1_122", "act1_123", "act1_124",
"act1_125", "act1_126", "act1_127", "act1_128", "act1_129", "act1_130",
"act1_131", "act1_132", "act1_133", "act1_134", "act1_135", "act1_136",
"act1_137", "act1_138", "act1_139", "act1_140", "act1_141", "act1_142",
"act1_143", "act1_144"), row.names = c(NA, 3L), class = "data.frame")
#
我做了以下情节:
我想在x轴上绘制1s的比例,而不是默认的1s和0s计数:在x轴上绘制睡眠人口的比例,在y轴上绘制一天中的时间。
我的问题是:如何计算比例?在使用调查数据时,我需要设置权重吗?
如何计算和报告活动报告的人口百分比?
我认为:
按整个人群划分报告活动的人数。
转换为百分比
将结果乘以100即可将其转换为百分比。
我瞄准这个情节
是否有一种紧凑的方法可以在一个ggplot()
中完成此操作?
非常感谢
答案 0 :(得分:0)
如果您只需要比例而不是总计,我认为您应该将sleepAct<-colSums(sleep[,])
更改为sleepAct<-colMeans(sleep[,])
。我知道您提到使用ggplot,但图位于核心R中。是的,如果要对更广泛的人群进行推断,则可能应该使用权重来计算加权平均值。