有没有办法将情节标题包装在 ggarrange 中?
Is there a way to wrap plot titles in ggarrange?
我试图想象学生通常来自哪个国家/地区,具体取决于课程。由于条形图需要每个程序都有不同的顺序,所以我选择单独生成图形并通过ggarrange显示,如下:
如您所见,情节标题被截断了。有解决办法吗?
我正在使用以下代码:
antal_hemvist_program<-function(x){totdata%>%filter(program==x)%>%ggplot(aes(x=fct_rev(fct_infreq(NYA_REGION))))+
geom_bar()+
theme(axis.title.y = element_blank(), axis.text.x=element_text(size=5))+ylab("Antal")+
coord_flip()+ggtitle(x)}
hv_n_program<-lapply(unique(totdata$program),antal_hemvist_program)
ggarrange(plotlist=hv_n_program)
数据小摘录:
structure(list(program = c("IPPE", "Ekonom", "IPPE", "Magister_FEK",
"Systemvetenskap", "Magister_FIN", "Ekonom", "Webmaster", "Maklarekonom",
"Maklarekonom", "IPPE", "Animation", "Magister_FEK", "Maklarekonom",
"IPPE", "IPPE", "IPPE", "IPPE", "Webmaster", "Systemvetenskap",
"Digitala_Medier", "Maklarekonom", "Magister_FEK", "Digitala_Medier",
"Ekonom", "IPPE", "Systemvetenskap", "Maklarekonom", "Systemvetenskap",
"IPPE", "Animation", "Maklarekonom", "IPPE", "Systemvetenskap",
"Personalekonomi", "Ekonom", "Personalekonomi", "Webmaster",
"Ekonom", "IPPE", "IPPE", "IPPE", "Personalekonomi", "Systemvetenskap",
"Personalekonomi", "Animation", "Digitala_Medier", "IPPE", "Ekonom",
"Maklarekonom"), NYA_REGION = structure(c(3L, 3L, 3L, 4L, 4L,
9L, 3L, 2L, 9L, 4L, 9L, 2L, 9L, 4L, 4L, 7L, 4L, 7L, 3L, 7L, 9L,
3L, 3L, 3L, 3L, 8L, 9L, 4L, 3L, 3L, 3L, 3L, 2L, 3L, 2L, 4L, 7L,
1L, 3L, 1L, 3L, 2L, 2L, 7L, 3L, 8L, 7L, 1L, 5L, 8L), .Label = c("UTANFÖR SVERIGE",
"ÖVRIGA LANDET", "STORGÖTEBORG", "oklart", "SÖDRA BOHUSLÄN",
"UDDEVALLA", "VÄSTERGÖTLAND", "VÄNERSBORG", "TROLLHÄTTAN", "NORRA BOHUSLÄN",
"DALSLAND"), class = c("ordered", "factor"))), row.names = c(NA,
-50L), class = c("tbl_df", "tbl", "data.frame"))
您可以将 plot.title.position = 'plot'
添加到对主题的调用中,这将使标题和副标题与整个情节而不是标题面板对齐。
antal_hemvist_program <- function(x {
totdata %>%
filter(program==x) %>%
ggplot(aes(x=fct_rev(fct_infreq(NYA_REGION)))) +
geom_bar() +
theme(axis.title.y = element_blank(),
axis.text.x=element_text(size=5),
plot.title.position = 'plot') +
ylab("Antal")+
coord_flip()+ggtitle(x)}
我试图想象学生通常来自哪个国家/地区,具体取决于课程。由于条形图需要每个程序都有不同的顺序,所以我选择单独生成图形并通过ggarrange显示,如下:
如您所见,情节标题被截断了。有解决办法吗?
我正在使用以下代码:
antal_hemvist_program<-function(x){totdata%>%filter(program==x)%>%ggplot(aes(x=fct_rev(fct_infreq(NYA_REGION))))+
geom_bar()+
theme(axis.title.y = element_blank(), axis.text.x=element_text(size=5))+ylab("Antal")+
coord_flip()+ggtitle(x)}
hv_n_program<-lapply(unique(totdata$program),antal_hemvist_program)
ggarrange(plotlist=hv_n_program)
数据小摘录:
structure(list(program = c("IPPE", "Ekonom", "IPPE", "Magister_FEK",
"Systemvetenskap", "Magister_FIN", "Ekonom", "Webmaster", "Maklarekonom",
"Maklarekonom", "IPPE", "Animation", "Magister_FEK", "Maklarekonom",
"IPPE", "IPPE", "IPPE", "IPPE", "Webmaster", "Systemvetenskap",
"Digitala_Medier", "Maklarekonom", "Magister_FEK", "Digitala_Medier",
"Ekonom", "IPPE", "Systemvetenskap", "Maklarekonom", "Systemvetenskap",
"IPPE", "Animation", "Maklarekonom", "IPPE", "Systemvetenskap",
"Personalekonomi", "Ekonom", "Personalekonomi", "Webmaster",
"Ekonom", "IPPE", "IPPE", "IPPE", "Personalekonomi", "Systemvetenskap",
"Personalekonomi", "Animation", "Digitala_Medier", "IPPE", "Ekonom",
"Maklarekonom"), NYA_REGION = structure(c(3L, 3L, 3L, 4L, 4L,
9L, 3L, 2L, 9L, 4L, 9L, 2L, 9L, 4L, 4L, 7L, 4L, 7L, 3L, 7L, 9L,
3L, 3L, 3L, 3L, 8L, 9L, 4L, 3L, 3L, 3L, 3L, 2L, 3L, 2L, 4L, 7L,
1L, 3L, 1L, 3L, 2L, 2L, 7L, 3L, 8L, 7L, 1L, 5L, 8L), .Label = c("UTANFÖR SVERIGE",
"ÖVRIGA LANDET", "STORGÖTEBORG", "oklart", "SÖDRA BOHUSLÄN",
"UDDEVALLA", "VÄSTERGÖTLAND", "VÄNERSBORG", "TROLLHÄTTAN", "NORRA BOHUSLÄN",
"DALSLAND"), class = c("ordered", "factor"))), row.names = c(NA,
-50L), class = c("tbl_df", "tbl", "data.frame"))
您可以将 plot.title.position = 'plot'
添加到对主题的调用中,这将使标题和副标题与整个情节而不是标题面板对齐。
antal_hemvist_program <- function(x {
totdata %>%
filter(program==x) %>%
ggplot(aes(x=fct_rev(fct_infreq(NYA_REGION)))) +
geom_bar() +
theme(axis.title.y = element_blank(),
axis.text.x=element_text(size=5),
plot.title.position = 'plot') +
ylab("Antal")+
coord_flip()+ggtitle(x)}