简体   繁体   English

highcharter-y轴上的类别

[英]highcharter - categories on the y axis

I am stumped! 我很沮丧! I am trying to do a simple scatter plot in highcharter with the categories on the y-axis and I can't figure it out. 我正在尝试在y轴上的类别中使用highcharter一个简单的散点图, highcharter我无法弄清楚。

Below is my code: 下面是我的代码:

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

It's currently set up to have no categories, y = 1 , but when I change y = Username in the hc_add_series it doesn't plot. 当前设置为没有类别, y = 1 ,但是当我在hc_add_series更改y = Username时,它不会显示。 I have type = "category" in the hc_yAxis . 我在hc_yAxis具有type = "category" Not sure why it is not working! 不知道为什么它不起作用!

Below is dput output: 以下是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}"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM