如何在同一工作区中显示这 5 个条形图?
How to display these 5 bar plot in the same workspace?
这是我正在使用的数据框
> 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
并排放置在同一个图中 window
这是我正在使用的数据框
> 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
并排放置在同一个图中 window