问题1
在平行坐标系中,group_by
不起作用,下面的数据集中有北京、上海、广州共三个城市的数据,但是最后展现出来的只有其中一个,可能正因为此,本该展现出来的图例也没显示出来。
library(echarts4r)
parallel<-data.frame(
date=c( 1, 2, 1, 2, 1, 2),
AQIindex=c(55, 25, 26, 85, 91, 65),
PM25=c(9, 11, 37, 62, 45, 27),
PM10=c(56, 21, 27, 71, 125, 78),
CO=c(0.46, 0.65, 1.163, 1.195, 0.82, 0.86),
NO2=c(18, 34, 27, 60, 34, 45),
SO2=c(6, 9, 13, 8, 23, 29),
level=c('良', '优', '优', '良', '良', '良'),
type=c('北京', '北京', '上海', '上海', '广州', '广州'))
parallel |>
group_by(type) |>
e_charts() |>
e_parallel(date,
AQIindex,
PM25,
PM10,
CO,
NO2,
SO2 ,
level,
opts = list(smooth = FALSE)) |>
e_legend(show = TRUE)|>
e_toolbox_feature(feature = "dataView")
问题2
使用双Y轴时,group_by
结合时间轴倒是起作用了,但是效果一言难尽,可以试试最后加或不加|>e_toolbox_feature(feature = "dataView")
出来的图都不一样。
data.ab <- data.frame(
type=c(
'A区域', 'A区域', 'A区域', 'A区域', 'A区域', 'A区域', 'A区域', 'A区域', 'A区域', 'A区域', 'A区域', 'A区域', 'B区域', 'B区域', 'B区域', 'B区域', 'B区域', 'B区域', 'B区域', 'B区域', 'B区域', 'B区域', 'B区域', 'B区域'),
month=c('1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月', '1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'),
Evaporation=c(2, 4.9, 7, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20, 6.4, 3.3,
2.6, 5.9, 9, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6, 2.3),
Precipitation=c(2.6, 5.9, 9, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6, 2.3,
2, 4.9, 7, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20, 6.4, 3.3),
Temperature=c(2, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23, 16.5, 12, 6.2,
2, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23, 16.5, 12, 6.2))
data.ab |>
group_by(type) |>
e_charts(month, timeline = TRUE) |>
e_bar(Evaporation, name = "蒸发量") |>
e_bar(Precipitation, name = "降水量") |>
e_line(Temperature, name = "平均温度", y_index = 1) |>
e_y_axis(
min = 0,
max = 250,
interval = 50,
name = "水量",
formatter = '{value} ml',
axisLine = list(show = TRUE),
axisTick = list(show = TRUE,
inside = TRUE )
) |>
e_y_axis(
index = 1,
min = 0,
max = 25,
interval = 5,
name = "温度",
formatter = '{value} °C'
) |>
e_toolbox_feature(feature = "dataView")
我的环境信息:R4.1.1,echarts4r_0.4.1
R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)
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] data.table_1.14.2 echarts4r_0.4.1
loaded via a namespace (and not attached):
[1] Rcpp_1.0.7 pillar_1.6.3 compiler_4.1.1 later_1.3.0 tools_4.1.1 digest_0.6.28
[7] jsonlite_1.7.2 evaluate_0.14 lifecycle_1.0.1 tibble_3.1.4 pkgconfig_2.0.3 rlang_0.4.11
[13] rstudioapi_0.13 shiny_1.7.0 cli_3.0.1 yaml_2.2.1 xfun_0.26 fastmap_1.1.0
[19] dplyr_1.0.7 knitr_1.35 generics_0.1.0 vctrs_0.3.8 htmlwidgets_1.5.4 tidyselect_1.1.1
[25] glue_1.4.2 R6_2.5.1 fansi_0.5.0 rmarkdown_2.11 purrr_0.3.4 magrittr_2.0.1
[31] promises_1.2.0.1 ellipsis_0.3.2 htmltools_0.5.2 mime_0.12 xtable_1.8-4 httpuv_1.6.3
[37] utf8_1.2.2 tinytex_0.34 crayon_1.4.1