有一个数据集,我想在highcharter
中创建一个带有离群值的箱形图。箱线图有效,但我似乎无法使异常值位于正确的x-axis
位置;由于某种原因,它们都在位置0上分组。箱形图是正确的,所以我不确定为什么离群值不遵循箱形图。
下面是我的代码:
library (highcharter)
Quote <- c(12,15,16,12,14,19,13,12,17,15,14,18,22,25,29,30,14,2,5,4)
Other <- c(30,35,36,12,18,35,39,41,42,43,45,31,37,35,32,31,34,36,32,15)
Shop <- c(2,1,5,4,6,9,5,4,7,8,1,5,4,3,5,4,1,5,15,19)
PN <- c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
Dat <- data.frame(Quote,Other,Shop, PN)
highchart() %>%
hc_add_series_boxplot(Dat$Quote, Dat$PN, name = "Quote Hold Time", color = "#FF8888", pointStart = 0) %>%
hc_add_series_boxplot(Dat$Other, Dat$PN, name = "Other Hold Time", color = "#E5A919", pointStart = 1) %>%
hc_add_series_boxplot(Dat$Shop, Dat$PN, name = "Shop Time", color = "#51C1BC", pointStart = 2) %>%
hc_xAxis(categories = c("Quote Hold","Other Hold","Shop Time"), labels = list(enabled = TRUE)) %>%
hc_yAxis(labels = list(format = "{value} days"), min = 0) %>%
hc_plotOptions(series = list(grouping = FALSE))
下面是问题的图片。所有scatter (outliers)
均位于x轴上的“报价保留”类别下。
答案 0 :(得分:1)
我发现它做了一些数据处理,因此所有数据都在一个系列之内。我无法弄清楚如何在给定的x列中使离群值与盒图具有相同的颜色,但是将它们全部变为相同的阴影也可以。
library (highcharter)
Quote <- c(12,15,16,12,14,19,13,12,17,15,14,18,22,25,29,30,14,2,5,4)
Other <- c(30,35,36,12,18,35,39,41,42,43,45,31,37,35,32,31,34,36,32,15)
Shop <- c(2,1,5,4,6,9,5,4,7,8,1,5,4,3,5,4,1,5,15,19)
PN <- c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
Dat <- data.frame(Quote,Other,Shop, PN)
Dat$QuoteType <- rep("Quote",nrow(Dat))
Dat$OtherType <- rep("Other",nrow(Dat))
Dat$ShopType <- rep("Shop",nrow(Dat))
Dat1 <- Dat[,c("Quote","QuoteType")]
colnames(Dat1) <- c("Value","Type")
Dat2 <- Dat[,c("Other","OtherType")]
colnames(Dat2) <- c("Value","Type")
Dat3 <- Dat[,c("Shop","ShopType")]
colnames(Dat3) <- c("Value","Type")
DatComb <- rbind(Dat1,Dat2,Dat3)
highchart() %>%
hc_add_series_boxplot(DatComb$Value, DatComb$Type, colors = c("#FF8888","#E5A919","#51C1BC"), name = "Test") %>%
hc_yAxis(labels = list(format = "{value} days"), min = 0) %>%
hc_plotOptions(boxplot = list(colorByPoint = TRUE), scatter = list(color = c("#A6BBC8")))