简体   繁体   English

在 R 中构建多个箱线图

[英]Constructing multiple boxplots in R

I have a movie data with respect to different genres.我有关于不同类型的电影数据。 My ultimate objective is to create a box plot of age wise ratings of films for different genres ie if action is one of the genres, I want to create a box plot of age wise ratings with each box plot representing a certain age group.我的最终目标是为不同类型的电影创建一个按年龄分级的箱线图,即如果动作是其中一种类型,我想创建一个按年龄分级的箱线图,每个箱线图代表某个年龄段。 I tried using the code :我尝试使用代码:

boxplot(cbind(Action_Subset$U_18_ratings,Action_Subset$Between_18_to_29_ratings,Action_Subset$Between_30_to_44_ratings,Action_Subset$Ratings_above_45))

I am able to create the box plots but unable to represent it according to different age groups.我能够创建箱线图,但无法根据不同的年龄组来表示它。

enter image description here在此处输入图片说明

How can I highlight which boxplot represents ratings for particular age group.如何突出显示哪个箱线图代表特定年龄组的评级。

Expecting that each column has same number of rows!期望每列具有相同的行数!

    data_boxplot <- cbind(Action_Subset$U_18_ratings,
                          Action_Subset$Between_18_to_29_ratings,
                          Action_Subset$Between_30_to_44_ratings,
                          Action_Subset$Ratings_above_45) %>% 
mutate(ID = row_number()) %>% 
pivot_longer(-ID)

p <- ggplot(dat_plot)+   geom_boxplot(aes(x = name, y = value, fill = name)) 
p

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM