问题是这样的:
echarts4r包里有个函数叫e_arrange可以把不同的图放一起展示,比如e_arrange(e1, e2, e3, e4, cols = 2, rows = 2)
就是指我画了e1/e2/e3/e4四个图并指定这四个图排成两行两列一起展示出来,但是输出为output: ioslides_presentation
时就变成所有图都排成一列了,我换成输出普通的output: html_document
却是正常的。
代码如下:
---
title: echarts 图形排列
output:
ioslides_presentation: default
html_document: default
---
## 两行两列
```{r, echo=FALSE}
library(echarts4r)
df <- data.frame(
x = seq(50),
y = rnorm(50, 10, 3),
z = rnorm(50, 11, 2),
w = rnorm(50, 9, 2)
)
e1 <- df |>
e_charts(x,
height = 200,
width = 200,
elementId = "图1") |>
e_line(z) |>
e_area(w)
funnel <-
data.frame(stage = c("View", "Click", "Purchase"),
value = c(80, 30, 20))
e2 <- funnel |>
e_charts(height = 200,
width = 200,
elementId = "图2") |>
e_funnel(value, stage)
liquid <- data.frame(val = c(0.6, 0.5, 0.4))
e3 <- liquid |>
e_charts(height = 200,
width = 200,
elementId = "图3") |>
e_liquid(val)
e4 <- df |>
e_charts(x, height = 200, width = 200) |>
e_polar() |>
e_angle_axis(x) |> # angle = x
e_radius_axis() |>
e_bar(y, coord_system = "polar") |>
e_scatter(z, coord_system = "polar") |>
e_connect(c("图1", "图2", "图3"))
e_arrange(e1, e2, e3, e4, cols = 2, rows = 2)
```
环境信息如下:
> sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936 LC_CTYPE=Chinese (Simplified)_China.936
[3] LC_MONETARY=Chinese (Simplified)_China.936 LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_China.936
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dplyr_1.0.7 echarts4r.maps_0.0.2 data.table_1.14.2 echarts4r_0.4.2
loaded via a namespace (and not attached):
[1] Rcpp_1.0.7 knitr_1.36 magrittr_2.0.1 tidyselect_1.1.1 xtable_1.8-4 R6_2.5.1 rlang_0.4.11
[8] fastmap_1.1.0 fansi_0.5.0 tools_4.1.1 xfun_0.26 utf8_1.2.2 htmltools_0.5.2 ellipsis_0.3.2
[15] yaml_2.2.1 digest_0.6.28 countrycode_1.3.0 tibble_3.1.5 lifecycle_1.0.1 crayon_1.4.2 shiny_1.7.1
[22] purrr_0.3.4 later_1.3.0 htmlwidgets_1.5.4 vctrs_0.3.8 promises_1.2.0.1 evaluate_0.14 mime_0.12
[29] glue_1.4.2 rmarkdown_2.11 compiler_4.1.1 pillar_1.6.4 generics_0.1.1 jsonlite_1.7.2 httpuv_1.6.3
[36] pkgconfig_2.0.3