我尝试用两个以上的组创建高图表密度。我找到了一种手动将它们逐一添加的方法,但必须有更好的方法来处理组。
示例:我想创建一个类似于下面的ggplot图表的highchart,而不需要将它们一一添加。有什么办法可以做到吗?
d
f <- data.frame(MEI = c(-2.031, -1.999, -1.945, -1.944, -1.875,
-1.873, -1.846, -2.031, -1.999, -1.945, -1.944, -1.875, -1.873,
-1.846, -2.031, -1.999, -1.945, -1.944, -1.875, -1.873, -1.846,
-2.031, -1.999, -1.945, -1.944, -1.875, -1.873, -1.846),
Count = c(10L,0L, 15L, 1L, 6L, 10L, 18L, 10L, 0L, 15L, 1L, 6L, 10L, 0L, 15L,
10L, 0L, 15L, 1L, 6L, 10L, 10L, 0L, 15L, 1L, 6L, 10L, 18L),
Region = c("MidWest", "MidWest", "MidWest", "MidWest", "MidWest", "MidWest", "MidWest",
"South", "South", "South", "South", "South", "South", "South",
"South", "South", "South", "NorthEast", "NorthEast", "NorthEast",
"NorthEast", "NorthEast", "NorthEast", "NorthEast", "NorthEast",
"NorthEast", "NorthEast", "NorthEast"))
df <- data.table(ddf)
df %>%ggplot() +
geom_density(aes(x=MEI, group=Region, fill=Region),alpha=0.5) +
xlab("MEI") +
ylab("Density")
hcdensity(df[Region=="NorthEast"]$MEI,area = TRUE) %>%
hc_add_series(density(df[Region=="MidWest"]$MEI), area = TRUE) %>%
hc_add_series(density(df[Region=="South"]$MEI), area = TRUE)