我在我的Rmarkdown中使用ggplot
来绘制多个图表。当我将markdown编织为HTML
我已将传奇放在top
- 左边和右边的一些传说出现裁剪
对于我的屏幕,图表的宽度看起来太小了 - 如何告诉Rmarkdown扩展到更大的宽度?
更新:添加Rmd文件内容。
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning=FALSE, message=FALSE)
library('knitr')
options(scipen=999)
library(rlang)
library(reshape2)
library(tidyr)
library(plyr)
library(dplyr)
library(ggplot2)
library(plotly)
library(ggthemes)
library(scales)
library(stringr)
library(RColorBrewer)
library(data.table)
library(forcats)
```
```{r}
text <- "
model,var,value,var2
M1,a,12211,a
M1,b1,10.21,B
M1,b2,5.07,B
M1,c1,41.8,C
M1,c2,58.2,C
M1,d,1.6,d
M2,a,11922,a
M2,b1,15.6,B
M2,b2,8.9,B
M2,c1,38.1,C
M2,c2,61.9,C
M2,d,1.8,d
M2,a,13101,a
M2,b1,9.21,B
M2,b2,6.56,B
M2,c1,36.07,C
M2,c2,63.93,C
M2,d,1.75,d
"
dft <- read.table(textConnection(text), sep=",", header = T)
```
```{r}
text <- "
MODEL,ENGINE,var,value,label,var2
ABCD A1601 F1S - QU1234,QUOINOK,varA_XX_Xxxx,11989,11989,varA_XX_Xxxx
ABCD A1601 F1S - QU1234,QUOINOK,varB_XX_xxxXx,1.87,1.87,varB_XX_xxxXx
ABCD A1601 F1S - QU1234,QUOINOK,varC,1.61,1.61,varC
ABCD A1601 F1S - QU1234,QUOINOK,varD_XXX_YYYYYYY_Zzz,0,0,VAR DEFH Xxxxxxx (%)
ABCD A1601 F1S - QU1234,QUOINOK,varE_XXX_YYYYYYY_Zzz,42.4,42.4,VAR DEFH Xxxxxxx (%)
ABCD A1601 F1S - QU1234,QUOINOK,varF_XXX_YYYYYYY_Zzz,26.6,26.6,VAR DEFH Xxxxxxx (%)
ABCD A1601 F1S - QU1234,QUOINOK,varH_XXX_YYYY_Zzz,31,31,VAR DEFH Xxxxxxx (%)
ABCD A1601 F1S - QU1234,QUOINOK,varG_XXX_YY_ZZZZ,3.4,3.4,VAR GIJK Xxxx (%)
ABCD A1601 F1S - QU1234,QUOINOK,varI_XXXX_YY_ZZZZZ,9.3,9.3,VAR GIJK Xxxx (%)
ABCD A1601 F1S - QU1234,QUOINOK,varJ_XXXX_Yyyy_ZZ_ZZZZZ,12.5,12.5,VAR GIJK Xxxx (%)
ABCD A1601 F1S - QU1234,QUOINOK,varK_Xxxx_YY_ZZZZZ,0,0,VAR GIJK Xxxx (%)
ABCD CPH1609 F3 - QU1234T,QUOINOK,varA_XX_Xxxx,10357,10357,varA_XX_Xxxx
ABCD CPH1609 F3 - QU1234T,QUOINOK,varB_XX_xxxXx,1.71,1.71,varB_XX_xxxXx
ABCD CPH1609 F3 - QU1234T,QUOINOK,varC,1.62,1.62,varC
ABCD CPH1609 F3 - QU1234T,QUOINOK,varD_XXX_YYYYYYY_Zzz,0,0,VAR DEFH Xxxxxxx (%)
ABCD CPH1609 F3 - QU1234T,QUOINOK,varE_XXX_YYYYYYY_Zzz,36.3,36.3,VAR DEFH Xxxxxxx (%)
ABCD CPH1609 F3 - QU1234T,QUOINOK,varF_XXX_YYYYYYY_Zzz,34,34,VAR DEFH Xxxxxxx (%)
ABCD CPH1609 F3 - QU1234T,QUOINOK,varH_XXX_YYYY_Zzz,29.7,29.7,VAR DEFH Xxxxxxx (%)
ABCD CPH1609 F3 - QU1234T,QUOINOK,varG_XXX_YY_ZZZZ,3.4,3.4,VAR GIJK Xxxx (%)
ABCD CPH1609 F3 - QU1234T,QUOINOK,varI_XXXX_YY_ZZZZZ,9.3,9.3,VAR GIJK Xxxx (%)
ABCD CPH1609 F3 - QU1234T,QUOINOK,varJ_XXXX_Yyyy_ZZ_ZZZZZ,13.6,13.6,VAR GIJK Xxxx (%)
ABCD CPH1609 F3 - QU1234T,QUOINOK,varK_Xxxx_YY_ZZZZZ,0,0,VAR GIJK Xxxx (%)
ABCD CPH1613 F3 - MOL2345,MOLTOVAST,varA_XX_Xxxx,12688.5,12688,varA_XX_Xxxx
ABCD CPH1613 F3 - MOL2345,MOLTOVAST,varB_XX_xxxXx,1.87,1.87,varB_XX_xxxXx
ABCD CPH1613 F3 - MOL2345,MOLTOVAST,varC,1.7,1.7,varC
ABCD CPH1613 F3 - MOL2345,MOLTOVAST,varD_XXX_YYYYYYY_Zzz,0,0,VAR DEFH Xxxxxxx (%)
ABCD CPH1613 F3 - MOL2345,MOLTOVAST,varE_XXX_YYYYYYY_Zzz,32.3,32.3,VAR DEFH Xxxxxxx (%)
ABCD CPH1613 F3 - MOL2345,MOLTOVAST,varF_XXX_YYYYYYY_Zzz,29.8,29.8,VAR DEFH Xxxxxxx (%)
ABCD CPH1613 F3 - MOL2345,MOLTOVAST,varH_XXX_YYYY_Zzz,37.9,37.9,VAR DEFH Xxxxxxx (%)
ABCD CPH1613 F3 - MOL2345,MOLTOVAST,varG_XXX_YY_ZZZZ,3.4,3.4,VAR GIJK Xxxx (%)
ABCD CPH1613 F3 - MOL2345,MOLTOVAST,varI_XXXX_YY_ZZZZZ,9.7,9.7,VAR GIJK Xxxx (%)
ABCD CPH1613 F3 - MOL2345,MOLTOVAST,varJ_XXXX_Yyyy_ZZ_ZZZZZ,11,11,VAR GIJK Xxxx (%)
ABCD CPH1613 F3 - MOL2345,MOLTOVAST,varK_Xxxx_YY_ZZZZZ,0,0,VAR GIJK Xxxx (%)
"
dft <- read.table(textConnection(text), sep=",", header = T)
p <- ggplot(dft, aes(x=MODEL, y=value, fill=var, label=label)) +
geom_col(aes(col = ENGINE), position=position_dodge(width = 0.9),
size=1.2) +
geom_text(position = position_dodge(width = 1),
show.legend = FALSE,
size = 3.5,
vjust=1
) +
facet_wrap( ~ var2, scales = "free_y", ncol = 1, drop = T) +
theme_custom_col +
scale_fill_brewer(palette = "Set3") +
scale_color_brewer(palette = "Paired") +
theme(
text = element_text(size=ggplotAxesLabelSize),
legend.position="top",
axis.text.x=element_text(angle = 20),
axis.text.y=element_blank()
) +
labs(y = "")
p
```
这在HTML中给出了以下图表(从HTML复制的图像)。可以看出,图例部分出现了裁剪。