第一个问题已解决
方法一:将数据week下面的汉字换成数字
方法二:需要把数据集里的week弄成有序因子,在作图
q$week<-factor(q$week,ordered=TRUE,
levels=c("周一","周二","周三","周四","周五","周六","周日"))
ggplot(q,aes(x=week,y=average,group=1))+geom_line()
现在求第二个题的解决办法,这个困扰我好久,折腾好久,我把代码贴上来,急求帮忙
> f=read.table('exam1.txt',header=TRUE) 【原始数据只有DAU和DNU两列】
> f
DNU DAU
1 23,359 23,584
2 29,125 37,209
3 45,742 60,785
4 33,565 56,760
5 19,571 40,076
6 22,344 44,035
7 24,410 48,275
8 23,405 49,236
9 24,420 54,015
10 35,244 68,920
11 32,493 68,093
12 18,378 48,058
13 19,528 49,373
14 19,393 50,068
15 14,815 45,926
16 15,699 48,858
17 24,932 61,003
18 20,123 56,292
19 11,588 39,747
20 10,522 37,738
21 9,641 35,939
22 10,026 35,905
23 10,702 38,920
24 14,026 45,603
25 11,781 40,871
26 6,735 28,238
27 7,314 28,225
28 7,282 28,043
29 6,848 27,183
30 8,804 31,558
31 10,714 35,537
32 10,343 35,237
33 5,931 24,818
> f$day<-1:nrow(f) 【添加标识列day】
> f
DNU DAU day
1 23,359 23,584 1
2 29,125 37,209 2
3 45,742 60,785 3
4 33,565 56,760 4
5 19,571 40,076 5
6 22,344 44,035 6
7 24,410 48,275 7
8 23,405 49,236 8
9 24,420 54,015 9
10 35,244 68,920 10
11 32,493 68,093 11
12 18,378 48,058 12
13 19,528 49,373 13
14 19,393 50,068 14
15 14,815 45,926 15
16 15,699 48,858 16
17 24,932 61,003 17
18 20,123 56,292 18
19 11,588 39,747 19
20 10,522 37,738 20
21 9,641 35,939 21
22 10,026 35,905 22
23 10,702 38,920 23
24 14,026 45,603 24
25 11,781 40,871 25
26 6,735 28,238 26
27 7,314 28,225 27
28 7,282 28,043 28
29 6,848 27,183 29
30 8,804 31,558 30
31 10,714 35,537 31
32 10,343 35,237 32
33 5,931 24,818 33
> melt(f,id.vars="day",variable.name="user",value.name="userdata")
day user userdata
1 1 DNU 23,359
2 2 DNU 29,125
3 3 DNU 45,742
4 4 DNU 33,565
5 5 DNU 19,571
6 6 DNU 22,344
7 7 DNU 24,410
8 8 DNU 23,405
9 9 DNU 24,420
10 10 DNU 35,244
11 11 DNU 32,493
12 12 DNU 18,378
13 13 DNU 19,528
14 14 DNU 19,393
15 15 DNU 14,815
16 16 DNU 15,699
17 17 DNU 24,932
18 18 DNU 20,123
19 19 DNU 11,588
20 20 DNU 10,522
21 21 DNU 9,641
22 22 DNU 10,026
23 23 DNU 10,702
24 24 DNU 14,026
25 25 DNU 11,781
26 26 DNU 6,735
27 27 DNU 7,314
28 28 DNU 7,282
29 29 DNU 6,848
30 30 DNU 8,804
31 31 DNU 10,714
32 32 DNU 10,343
33 33 DNU 5,931
34 1 DAU 23,584
35 2 DAU 37,209
36 3 DAU 60,785
37 4 DAU 56,760
38 5 DAU 40,076
39 6 DAU 44,035
40 7 DAU 48,275
41 8 DAU 49,236
42 9 DAU 54,015
43 10 DAU 68,920
44 11 DAU 68,093
45 12 DAU 48,058
46 13 DAU 49,373
47 14 DAU 50,068
48 15 DAU 45,926
49 16 DAU 48,858
50 17 DAU 61,003
51 18 DAU 56,292
52 19 DAU 39,747
53 20 DAU 37,738
54 21 DAU 35,939
55 22 DAU 35,905
56 23 DAU 38,920
57 24 DAU 45,603
58 25 DAU 40,871
59 26 DAU 28,238
60 27 DAU 28,225
61 28 DAU 28,043
62 29 DAU 27,183
63 30 DAU 31,558
64 31 DAU 35,537
65 32 DAU 35,237
66 33 DAU 24,818
警告信息:
attributes are not identical across measure variables; they will be dropped 【这个警告说测量变量属性不一致是什么意思?DNU和DAU不一致?】
> ggplot(f,aes(x=day,y=userdata,group=user))+geom_line()
错误于eval(expr, envir, enclos) : 找不到对象'userdata' 【总是说找不到userdata,之前也命名过啊,,怎么回事??】
|