r-如何在同一工作空间中显示这5个条形图



这是我正在使用的数据帧

> Age_Time
# A tibble: 268 x 2
Age     Time      
<chr>   <chr>     
1 [18,24[ 1-5 hours 
2 [10,18[ 1-5 hours 
3 [18,24[ >10 hours 
4 [18,24[ 5-10 hours
5 [18,24[ 5-10 hours
6 [24,34[ 1-5 hours 
7 [18,24[ 5-10 hours
8 [18,24[ 5-10 hours
9 [24,34[ 0 hours   
10 [18,24[ 5-10 hours
# ... with 258 more rows
> str(head(Age_Time))
tibble [6 x 2] (S3: tbl_df/tbl/data.frame)
$ Age : chr [1:6] "[18,24[" "[10,18[" "[18,24[" "[18,24[" ...
$ Time: chr [1:6] "1-5 hours" "1-5 hours" ">10 hours" "5-10 hours" ...

我分别制作了5个条形图,如下所示,我想把它们放在同一个工作区,这样它们就可以一起显示

Age_time=Survey[3:4]
Time1=Age_time %>%
filter(Time=="0 hours")
b1 <- barplot(table(Time1$Age),col=colors,ylim=c(0,10),main = "No time spent on Social Media")
text(b1[,1],table(Time1$Age)-1,table(Time1$Age))
Time2=Age_time %>%
filter(Time== "<1 hours")
b2 <- barplot(table(Time2$Age),col=colors,ylim=c(0,20),main="Less than an hour spent on Social Media")
text(b2[,1],table(Time2$Age)-1,table(Time2$Age))
Time3=Age_time %>%
filter(Time =="1-5 hours")
b3 <- barplot(table(Time3$Age),col=colors,ylim=c(0,100),main="1 to 5 hours on Social Media")
text(b3[,1],table(Time3$Age)-1,table(Time3$Age))
Time4=Age_time %>%
filter(Time =="5-10 hours")
b4 <- barplot(table(Time4$Age),col=colors,ylim=c(0,90),main="5 to 10 hours on Social Media")
text(b4[,1],table(Time4$Age)-1,table(Time4$Age))
Time5=Age_time %>%
filter(Time ==">10 hours")
b5 <- barplot(table(Time5$Age),col=colors,ylim=c(0,40),main="More than 10 hours on Social Media")
text(b5[,1],table(Time5$Age)-1,table(Time5$Age))

例如,我不介意更改整个代码并使用ggplot,只要我最终得到我想要的结果,即并排获得5个数字(不使用共享轴(

尝试将其放置在第一个barplot之前

par(mfrow=c(1,5))

这将把所有5个barplot并排放置在同一绘图窗口中

最新更新