我是R的新手,我想弄清楚如何创建成簇的条形图,这是对电影的平均兴趣,但要按性别分开。 这是我的数据框:
i gender film interest
1 male 1 22
2 male 1 13
3 male 1 16
4 male 1 10
5 male 1 18
6 male 1 24
7 male 1 13
8 male 1 14
9 male 1 19
10 male 1 23
11 male 2 37
12 male 2 20
13 male 2 16
14 male 2 28
15 male 2 27
16 male 2 18
17 male 2 32
18 male 2 24
19 male 2 21
20 male 2 35
21 female 1 3
22 female 1 15
23 female 1 5
24 female 1 16
25 female 1 13
26 female 1 20
27 female 1 11
28 female 1 19
29 female 1 15
30 female 1 7
31 female 2 30
32 female 2 25
33 female 2 31
34 female 2 36
35 female 2 23
36 female 2 14
37 female 2 21
38 female 2 31
39 female 2 22
40 female 2 14
以下是使用的脚本:
movies<-read.csv(file.choose())
t.test(interest~film, data = movies)
names(movies)
str(movies)
movies$ï..gender = factor(movies$ï..gender, levels=c(1,2),
labels=c("male","female"))
with(movies, table(film,interest))
summary(movies)
movie.types<-split(movies$interest, movies$film)
boxplot(movie.types)
movie.mean<-sapply(movie.types,mean)
barplot(movie.mean, col = "red", main = "Mean Interest by Film",
ylim=c(0,30), names.arg = c("Bridget Jones Diary","Memento"))
这是我制作的条形图,我需要制作一个聚类图以按性别划分: