使用拼凑::wrap_plots()增加绘图高度
我正在使用patchwork::wrap_plots()输出ggplots列表。由于该列表是动态的,并且不总是包含相同数量的图,因此我需要找到一种方法来调整图的高度,以便一些图不会被压扁 服务器部分的代码使用拼凑::wrap_plots()增加绘图高度,r,shiny,shinydashboard,patchwork,R,Shiny,Shinydashboard,Patchwork,我正在使用patchwork::wrap_plots()输出ggplots列表。由于该列表是动态的,并且不总是包含相同数量的图,因此我需要找到一种方法来调整图的高度,以便一些图不会被压扁 服务器部分的代码 output$attribute_plot<- renderPlot(analyze_demographics(demographics_table, selectedDemo
output$attribute_plot<- renderPlot(analyze_demographics(demographics_table,
selectedDemographicAttribute(),
categories_df))
output$attribute_category_plot<-renderPlot(analyze_demographics(summary_demographics_table,
selectedDemographicAttribute(),
categories_df))
output$display_questions_table<-renderTable(questions_table[,1:3],
rownames=FALSE,
colnames=FALSE)
输出如下所示。
如你所见,右边的图表被压扁了
图的代码
plot_list<-list()
for(n in 2:ncol(temp_df)){
df<-data.frame(temp_df[,n])
parameter<-colnames(temp_df)[n]
rownames(df)<-rownames(temp_df)
names(df)[1]<-parameter
g<-ggplot(df) +
geom_point(aes(x=rownames(df),y=df[,1]))+
coord_flip()+
geom_segment(aes(yend=df[,1],xend=rownames(df),x=rownames(df),y=0)) +
labs(title = paste(parameter),
y='Average Score',
caption = attribute) +
theme(legend.position = 'none',
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_rect(fill = color_palette[5]),
plot.title=element_text(size=18,
face="bold",
family="Arial",
color=color_palette[1],
hjust=0.5,
lineheight=1.2), # title
axis.title.y=element_blank(), # X axis title
axis.title.x=element_text(size=12,family="Arial",color=color_palette[1]),
axis.text.x=element_text(size=10,
family="Arial",
color=color_palette[3],
vjust=.5),
axis.text.y=element_text(size=15,
family="Arial",
lineheight = 20,
color=color_palette[1]),
axis.ticks.y = element_blank())+
scale_x_discrete()
g
plot_list[[n-1]]<-g
}
plot_length<-length(plot_list)
multi_plot<-patchwork::wrap_plots(plot_list,nrow=plot_length,ncol=1)
plot\u列表
plot_list<-list()
for(n in 2:ncol(temp_df)){
df<-data.frame(temp_df[,n])
parameter<-colnames(temp_df)[n]
rownames(df)<-rownames(temp_df)
names(df)[1]<-parameter
g<-ggplot(df) +
geom_point(aes(x=rownames(df),y=df[,1]))+
coord_flip()+
geom_segment(aes(yend=df[,1],xend=rownames(df),x=rownames(df),y=0)) +
labs(title = paste(parameter),
y='Average Score',
caption = attribute) +
theme(legend.position = 'none',
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_rect(fill = color_palette[5]),
plot.title=element_text(size=18,
face="bold",
family="Arial",
color=color_palette[1],
hjust=0.5,
lineheight=1.2), # title
axis.title.y=element_blank(), # X axis title
axis.title.x=element_text(size=12,family="Arial",color=color_palette[1]),
axis.text.x=element_text(size=10,
family="Arial",
color=color_palette[3],
vjust=.5),
axis.text.y=element_text(size=15,
family="Arial",
lineheight = 20,
color=color_palette[1]),
axis.ticks.y = element_blank())+
scale_x_discrete()
g
plot_list[[n-1]]<-g
}
plot_length<-length(plot_list)
multi_plot<-patchwork::wrap_plots(plot_list,nrow=plot_length,ncol=1)