highcharter - y 轴上的类别
highcharter - categories on the y axis
我难住了!我想在 highcharter
中用 y 轴上的类别做一个简单的散点图,但我无法弄清楚。
下面是我的代码:
library(highcharter)
LoginTrackerAggHourly <- aggregate(LoginTracker$X1, by = list(LoginTracker$Time,LoginTracker$Username),FUN=sum)
colnames(LoginTrackerAggHourly)[which(names(LoginTrackerAggHourly) == "Group.1")] <- "Time"
colnames(LoginTrackerAggHourly)[which(names(LoginTrackerAggHourly) == "Group.2")] <- "Username"
colnames(LoginTrackerAggHourly)[which(names(LoginTrackerAggHourly) == "x")] <- "Aggregate"
hc <- highchart() %>%
hc_chart(zoomType = "x") %>%
hc_yAxis(type = "category", title = list(text = "Dashboard Visits", style = list(color = "#ffffff")), labels = list(style = list(color = "#ffffff"))) %>%
hc_xAxis(title = list(text = "Hour of day", style = list(color = "#ffffff")), labels = list(style = list(color = "#ffffff"))) %>%
hc_add_series(data = LoginTrackerAggHourly, hcaes(x = Time, y = 1, size = Aggregate, group = Username),
type = "scatter",
tooltip = list(headerFormat = "<b>Site: {point.Username} <b><br>",
pointFormat = "Visits: {point.Aggregate} on Hour {point.Time}"))
hc
它目前设置为没有类别,y = 1
,但是当我在 hc_add_series
中更改 y = Username
时,它没有绘制。我在 hc_yAxis
中有 type = "category"
。不确定为什么它不起作用!
下面是dput
输出:
dput(LoginTracker)
structure(list(X1 = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), Username = c("Maastricht",
"Monroe", "Monroe", "Monroe", "Singapore", "Singapore", "Singapore",
"Singapore", "Singapore", "Singapore", "Maastricht", "Maastricht",
"Maastricht", "Maastricht", "Maastricht", "Monroe", "Maastricht",
"Maastricht", "Central", "Maastricht", "Maastricht", "Monroe",
"Central", "Central", "Monroe", "Monroe", "Central", "Phoenix",
"Maastricht", "Maastricht", "Maastricht", "Temp", "Monroe", "Monroe",
"Central", "Temp", "Central", "Singapore", "Singapore", "Singapore",
"Singapore", "Singapore", "Singapore", "Maastricht", "Maastricht",
"Maastricht", "Maastricht", "Maastricht", "Singapore", "Maastricht",
"Monroe", "Maastricht", "Maastricht", "Maastricht", "KammererJ"
), Date = structure(c(-712889, -712889, -712889, -712889, -712889,
-712888, -712888, -712888, -712888, -712888, -712888, -712888,
-712888, -712888, -712888, -712888, -712888, -712888, -712888,
-712888, -712888, -712888, -712888, -712888, -712888, -712888,
-712888, -712888, -712887, -712887, -712887, -712887, -712887,
-712887, -712887, -712887, -712887, -712887, -712887, -712887,
-712887, -712887, -712887, -712886, -712886, -712886, -712886,
-712886, -712886, -712886, -712886, -712886, -712886, -712886,
-712886), class = "Date"), Time = c("11", "14", "15", "15", "22",
"01", "01", "02", "02", "02", "02", "03", "03", "04", "07", "07",
"08", "09", "11", "11", "12", "14", "15", "15", "15", "15", "16",
"17", "03", "05", "05", "07", "07", "09", "13", "16", "16", "19",
"19", "19", "20", "20", "20", "02", "02", "02", "02", "02", "04",
"04", "09", "10", "11", "11", "12")), .Names = c("X1", "Username",
"Date", "Time"), row.names = c(3L, 5L, 10L, 11L, 13L, 14L, 15L,
16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 26L, 29L, 30L, 33L,
39L, 41L, 43L, 45L, 46L, 48L, 52L, 53L, 54L, 55L, 56L, 57L, 58L,
62L, 71L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L,
85L, 86L, 87L, 88L, 90L, 91L, 93L, 94L, 98L), class = "data.frame")
LoginTrackerAggHourly <- aggregate(LoginTracker$X1, by = list(LoginTracker$Time,LoginTracker$Username),FUN=sum)
colnames(LoginTrackerAggHourly)[which(names(LoginTrackerAggHourly) == "Group.1")] <- "Time"
colnames(LoginTrackerAggHourly)[which(names(LoginTrackerAggHourly) == "Group.2")] <- "Username"
colnames(LoginTrackerAggHourly)[which(names(LoginTrackerAggHourly) == "x")] <- "Aggregate"
LoginTrackerAggHourly$Username <- as.factor(LoginTrackerAggHourly$Username)
LoginTrackerAggHourly <- mutate(LoginTrackerAggHourly, typenum = as.numeric(LoginTrackerAggHourly$Username) -1)
lvls <- LoginTrackerAggHourly %>% pull(Username) %>% levels()
max <- length(lvls) - 1
hc <- highchart() %>%
hc_chart(zoomType = "x") %>%
hc_yAxis(categories = lvls, title = list(text = "Dashboard Visits", style = list(color = "#ffffff")), labels = list(style = list(color = "#ffffff")), min = 0, max = max) %>%
hc_xAxis(title = list(text = "Hour of day", style = list(color = "#ffffff")), labels = list(style = list(color = "#ffffff")), step = 1) %>%
hc_add_series(data = LoginTrackerAggHourly, hcaes(x = Time, y = typenum, size = Aggregate, group = Username),
type = "scatter",
tooltip = list(headerFormat = "<b>Site: {point.Username} <b><br>",
pointFormat = "Visits: {point.Aggregate} on Hour {point.Time}"))
我难住了!我想在 highcharter
中用 y 轴上的类别做一个简单的散点图,但我无法弄清楚。
下面是我的代码:
library(highcharter)
LoginTrackerAggHourly <- aggregate(LoginTracker$X1, by = list(LoginTracker$Time,LoginTracker$Username),FUN=sum)
colnames(LoginTrackerAggHourly)[which(names(LoginTrackerAggHourly) == "Group.1")] <- "Time"
colnames(LoginTrackerAggHourly)[which(names(LoginTrackerAggHourly) == "Group.2")] <- "Username"
colnames(LoginTrackerAggHourly)[which(names(LoginTrackerAggHourly) == "x")] <- "Aggregate"
hc <- highchart() %>%
hc_chart(zoomType = "x") %>%
hc_yAxis(type = "category", title = list(text = "Dashboard Visits", style = list(color = "#ffffff")), labels = list(style = list(color = "#ffffff"))) %>%
hc_xAxis(title = list(text = "Hour of day", style = list(color = "#ffffff")), labels = list(style = list(color = "#ffffff"))) %>%
hc_add_series(data = LoginTrackerAggHourly, hcaes(x = Time, y = 1, size = Aggregate, group = Username),
type = "scatter",
tooltip = list(headerFormat = "<b>Site: {point.Username} <b><br>",
pointFormat = "Visits: {point.Aggregate} on Hour {point.Time}"))
hc
它目前设置为没有类别,y = 1
,但是当我在 hc_add_series
中更改 y = Username
时,它没有绘制。我在 hc_yAxis
中有 type = "category"
。不确定为什么它不起作用!
下面是dput
输出:
dput(LoginTracker)
structure(list(X1 = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), Username = c("Maastricht",
"Monroe", "Monroe", "Monroe", "Singapore", "Singapore", "Singapore",
"Singapore", "Singapore", "Singapore", "Maastricht", "Maastricht",
"Maastricht", "Maastricht", "Maastricht", "Monroe", "Maastricht",
"Maastricht", "Central", "Maastricht", "Maastricht", "Monroe",
"Central", "Central", "Monroe", "Monroe", "Central", "Phoenix",
"Maastricht", "Maastricht", "Maastricht", "Temp", "Monroe", "Monroe",
"Central", "Temp", "Central", "Singapore", "Singapore", "Singapore",
"Singapore", "Singapore", "Singapore", "Maastricht", "Maastricht",
"Maastricht", "Maastricht", "Maastricht", "Singapore", "Maastricht",
"Monroe", "Maastricht", "Maastricht", "Maastricht", "KammererJ"
), Date = structure(c(-712889, -712889, -712889, -712889, -712889,
-712888, -712888, -712888, -712888, -712888, -712888, -712888,
-712888, -712888, -712888, -712888, -712888, -712888, -712888,
-712888, -712888, -712888, -712888, -712888, -712888, -712888,
-712888, -712888, -712887, -712887, -712887, -712887, -712887,
-712887, -712887, -712887, -712887, -712887, -712887, -712887,
-712887, -712887, -712887, -712886, -712886, -712886, -712886,
-712886, -712886, -712886, -712886, -712886, -712886, -712886,
-712886), class = "Date"), Time = c("11", "14", "15", "15", "22",
"01", "01", "02", "02", "02", "02", "03", "03", "04", "07", "07",
"08", "09", "11", "11", "12", "14", "15", "15", "15", "15", "16",
"17", "03", "05", "05", "07", "07", "09", "13", "16", "16", "19",
"19", "19", "20", "20", "20", "02", "02", "02", "02", "02", "04",
"04", "09", "10", "11", "11", "12")), .Names = c("X1", "Username",
"Date", "Time"), row.names = c(3L, 5L, 10L, 11L, 13L, 14L, 15L,
16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 26L, 29L, 30L, 33L,
39L, 41L, 43L, 45L, 46L, 48L, 52L, 53L, 54L, 55L, 56L, 57L, 58L,
62L, 71L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L,
85L, 86L, 87L, 88L, 90L, 91L, 93L, 94L, 98L), class = "data.frame")
LoginTrackerAggHourly <- aggregate(LoginTracker$X1, by = list(LoginTracker$Time,LoginTracker$Username),FUN=sum)
colnames(LoginTrackerAggHourly)[which(names(LoginTrackerAggHourly) == "Group.1")] <- "Time"
colnames(LoginTrackerAggHourly)[which(names(LoginTrackerAggHourly) == "Group.2")] <- "Username"
colnames(LoginTrackerAggHourly)[which(names(LoginTrackerAggHourly) == "x")] <- "Aggregate"
LoginTrackerAggHourly$Username <- as.factor(LoginTrackerAggHourly$Username)
LoginTrackerAggHourly <- mutate(LoginTrackerAggHourly, typenum = as.numeric(LoginTrackerAggHourly$Username) -1)
lvls <- LoginTrackerAggHourly %>% pull(Username) %>% levels()
max <- length(lvls) - 1
hc <- highchart() %>%
hc_chart(zoomType = "x") %>%
hc_yAxis(categories = lvls, title = list(text = "Dashboard Visits", style = list(color = "#ffffff")), labels = list(style = list(color = "#ffffff")), min = 0, max = max) %>%
hc_xAxis(title = list(text = "Hour of day", style = list(color = "#ffffff")), labels = list(style = list(color = "#ffffff")), step = 1) %>%
hc_add_series(data = LoginTrackerAggHourly, hcaes(x = Time, y = typenum, size = Aggregate, group = Username),
type = "scatter",
tooltip = list(headerFormat = "<b>Site: {point.Username} <b><br>",
pointFormat = "Visits: {point.Aggregate} on Hour {point.Time}"))