如何在echarts4r包中制作堆积图?
如果我添加第二个y轴 - 它会在同一个图中添加新系列。
data.frame(x=LETTERS[1:5],y=1:5,
z=6:10)%>%
e_charts(x)%>%
e_line(y)%>%
e_line(z, y.index = 1)
答案 0 :(得分:1)
因为你在两个不同的Y轴上绘图(y.index = 1
)所以你将无法叠加它们,如果你在同一个Y轴上绘制它们,你将能够叠加它们。
data.frame(x=LETTERS[1:5],
y=1:5,
z=6:10
) %>%
e_charts(x) %>%
e_line(y, stack = "stack") %>%
e_line(z, stack = "stack")
请注意,您不必将“堆栈”传递给stack
参数,您可以传递任何所需的内容,这样可以堆叠不同的组。
data.frame(x = LETTERS[1:5],
y=1:5,
z = 6:10,
w = rnorm(5, 4, 1),
e = rnorm(5, 5, 2)
) %>%
e_charts(x) %>%
e_bar(y, stack = "stack") %>%
e_bar(z, stack = "stack") %>%
e_bar(w , stack = "grp2") %>%
e_bar(e, stack = "grp2")
为什么在文档中没有明确说明此选项的原因:ECharts附带了数百个(如果不是数千个)选项,将它们列为全部,因为参数几乎不可能。但是,所有选项均可在包装中找到;请参阅official documention
修改强>
您可以在多个Y轴上堆叠,但不能跨越它们。这也有效:
data.frame(x = LETTERS[1:5],
y=1:5,
z = 6:10,
w = rnorm(5, 4, 1),
e = rnorm(5, 5, 2)
) %>%
e_charts(x) %>%
e_bar(y, stack = "stack") %>% # defaults to y.index = 0
e_bar(z, stack = "stack") %>% # defaults to y.index = 0
e_bar(w , stack = "grp2", y.index = 1) %>% # secondary axis + stack
e_bar(e, stack = "grp2", y.index = 1) # secondary axis + stack
对于您最初想要的多个图表,一个x轴,多个Y轴,一页上有2个图:
df <- data.frame(x=LETTERS[1:5],y=1:5, z=6:10)
df %>%
e_charts(x) %>%
e_line(y) %>%
e_line(z, y.index = 1, x.index = 1) %>%
e_y_axis(gridIndex = 1) %>%
e_x_axis(gridIndex = 1) %>%
e_grid(height = "35%") %>%
e_grid(height = "35%", top = "50%") %>%
e_datazoom(x.index = c(0, 1)) # brush http://echarts4r.john-coene.com/articles/brush.html