在 ggplot 中减少面板 height/width 并在 R Markdown 中裁剪白色 space
Reducing panel height/width in a ggplot & cropping the white space in R Markdown
请不要关闭它并告诉我答案在 Remove space between plotted data and the axes 上,因为那不是同一个情节并且在这里不起作用。使用 expand 使条变大。
我最初的问题是面板太多,详见下文,我使用
解决了
library(patchwork)
plot11f + plot_layout(ncol = 1,nrow =5)
我能够得到灰色较少的漂亮的瘦图,但是在我的降价文档中,它下面有一个大的白色 space。使用 plot.margins 没有帮助,它砍掉了我的轴标签并且仍然给出了大白 space.
--- 原题---
我已经生成了以下 ggplot(下面的代码和虚拟数据),但我想降低灰色面板位的高度(我用红色涂鸦的地方)以使图形更短(我什至可能进一步缩小条的宽度但是需要知道如何先减少灰色背景面板)。
tableq11f<-data.frame(Q11f<-c("A","B","C","D","E"), percent<-c(0.03,0.07,0.22,0.46,0.22))
plot11f<-ggplot(data=tableq11, aes(x=percent, y="Q11", fill=Q11f))+
geom_col(position = "fill", show.legend = FALSE, width=0.5)+
scale_fill_brewer(palette="Blues")+theme(axis.title.x=element_blank(),
axis.title.y=element_blank(),axis.text.y=element_blank(),axis.ticks.y=element_blank())+
scale_x_continuous(labels = scales::percent)
更多类似内容
空的 space 在那里是因为您使用拼凑来创建绘图网格和四个空行,这不是实现目标的合适方法。相反,使用 scale_y_discrete(expand = expansion(mult = .075))
减少条形图和绘图边距之间的 space 并减小 geom_col()
中条形图的宽度,最后如评论中所述,为在降价块选项中绘制。
---
title: "Untitled"
output: word_document
---
```{r, echo=FALSE, fig.width=5, fig.asp = .15}
library(ggplot2)
tableq11f<-data.frame(Q11f=c("A","B","C","D","E"), percent=c(0.03,0.07,0.22,0.46,0.22))
ggplot(data = tableq11f, aes(x = percent, y = "Q11", fill = Q11f)) +
geom_col(position = "fill",
show.legend = FALSE,
width = 0.1) +
scale_fill_brewer(palette = "Blues") +
theme(
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank()
) +
scale_x_continuous(labels = scales::percent) +
scale_y_discrete(expand = expansion(mult = .075))
```
给出:
请不要关闭它并告诉我答案在 Remove space between plotted data and the axes 上,因为那不是同一个情节并且在这里不起作用。使用 expand 使条变大。
我最初的问题是面板太多,详见下文,我使用
解决了library(patchwork)
plot11f + plot_layout(ncol = 1,nrow =5)
我能够得到灰色较少的漂亮的瘦图,但是在我的降价文档中,它下面有一个大的白色 space。使用 plot.margins 没有帮助,它砍掉了我的轴标签并且仍然给出了大白 space.
--- 原题--- 我已经生成了以下 ggplot(下面的代码和虚拟数据),但我想降低灰色面板位的高度(我用红色涂鸦的地方)以使图形更短(我什至可能进一步缩小条的宽度但是需要知道如何先减少灰色背景面板)。
tableq11f<-data.frame(Q11f<-c("A","B","C","D","E"), percent<-c(0.03,0.07,0.22,0.46,0.22))
plot11f<-ggplot(data=tableq11, aes(x=percent, y="Q11", fill=Q11f))+
geom_col(position = "fill", show.legend = FALSE, width=0.5)+
scale_fill_brewer(palette="Blues")+theme(axis.title.x=element_blank(),
axis.title.y=element_blank(),axis.text.y=element_blank(),axis.ticks.y=element_blank())+
scale_x_continuous(labels = scales::percent)
更多类似内容
空的 space 在那里是因为您使用拼凑来创建绘图网格和四个空行,这不是实现目标的合适方法。相反,使用 scale_y_discrete(expand = expansion(mult = .075))
减少条形图和绘图边距之间的 space 并减小 geom_col()
中条形图的宽度,最后如评论中所述,为在降价块选项中绘制。
---
title: "Untitled"
output: word_document
---
```{r, echo=FALSE, fig.width=5, fig.asp = .15}
library(ggplot2)
tableq11f<-data.frame(Q11f=c("A","B","C","D","E"), percent=c(0.03,0.07,0.22,0.46,0.22))
ggplot(data = tableq11f, aes(x = percent, y = "Q11", fill = Q11f)) +
geom_col(position = "fill",
show.legend = FALSE,
width = 0.1) +
scale_fill_brewer(palette = "Blues") +
theme(
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank()
) +
scale_x_continuous(labels = scales::percent) +
scale_y_discrete(expand = expansion(mult = .075))
```
给出: