Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在R highcharter(可能的其他软件包)中绘制3级向下展开图_Javascript_R_Highcharts_Drilldown - Fatal编程技术网

Javascript 如何在R highcharter(可能的其他软件包)中绘制3级向下展开图

Javascript 如何在R highcharter(可能的其他软件包)中绘制3级向下展开图,javascript,r,highcharts,drilldown,Javascript,R,Highcharts,Drilldown,今天我用highcharter套餐开始了我的冒险。我对深入调查情节感兴趣 (快速检查不带r的情况下要创建的内容) R代码,带有两个级别的向下展开图的工作示例 library("dplyr") library("purrr") library("highcharter") df <- data_frame( name = c("Animals", "Fruits", "Cars"), y = c(5, 2, 4), drilldown = tolower(name) ) df

今天我用highcharter套餐开始了我的冒险。我对深入调查情节感兴趣

(快速检查不带r的情况下要创建的内容)

R代码,带有两个级别的向下展开图的工作示例

library("dplyr")
library("purrr")
library("highcharter")

df <- data_frame(
  name = c("Animals", "Fruits", "Cars"),
  y = c(5, 2, 4),
  drilldown = tolower(name)
)
df


ds <- list.parse3(df)
names(ds) <- NULL
str(ds)
hc <- highchart() %>%
  hc_chart(type = "column") %>%
  hc_title(text = "Basic drilldown") %>%
  hc_xAxis(type = "category") %>%
  hc_legend(enabled = FALSE) %>%
  hc_plotOptions(
    series = list(
      boderWidth = 0,
      dataLabels = list(enabled = TRUE)
    )
  ) %>%
  hc_add_series(
    name = "Things",
    colorByPoint = TRUE,
    data = ds
  )


dfan <- data_frame(
  name = c("Cats", "Dogs", "Cows", "Sheep", "Pigs"),
  value = c(4, 3, 1, 2, 1)
)
dffru <- data_frame(
  name = c("Apple", "Organes"),
  value = c(4, 2)
)
dfcar <- data_frame(
  name = c("Toyota", "Opel", "Volkswage"),
  value = c(4, 2, 2)
)
second_el_to_numeric <- function(ls){
  map(ls, function(x){
    x[[2]] <- as.numeric(x[[2]])
    x
  })
}
dsan <- second_el_to_numeric(list.parse2(dfan))
dsfru <- second_el_to_numeric(list.parse2(dffru))
dscar <- second_el_to_numeric(list.parse2(dfcar))
hc <- hc %>%
  hc_drilldown(
    allowPointDrilldown = TRUE,
    series = list(
      list(
        id = "animals",
        data = dsan
      ),
      list(
        id = "fruits",
        data = dsfru
      ),
      list(
        id = "cars",

        data = dscar
      )
    )
  )
hc
库(“dplyr”)
图书馆(“purrr”)
图书馆(“高宪章”)
df%
hc_图例(启用=错误)%>%
hc\u绘图选项(
系列=列表(
博德宽度=0,
dataLabels=list(enabled=TRUE)
)
) %>%
hc_添加_系列(
name=“Things”,
colorByPoint=TRUE,
数据=ds
)

dfan如果您想要一个多层次的深入分析,您必须将深入分析的id设置为数据点,就像在纯js highcharts中一样

例如: 最重要的是:

drilldown: {
        series: [{
            id: 'animals',
            name: 'Animals',
            data: [{
                name: 'Cats',
                y: 4,
                drilldown: 'cats'
            }, ['Dogs', 2],
                ['Cows', 1],
                ['Sheep', 2],
                ['Pigs', 1]
            ]
        }, {

            id: 'cats',
            data: [1, 2, 3]
        }]
    }
您可以在这里看到,您的数据点不仅是数字,而且是包含链接到深入系列的对象

使用Highcharter的示例-简化,但您应该了解:

hc <- highchart() %>%
    hc_chart(type="column") %>%
    hc_xAxis(type="category") %>%
    hc_add_series(
        name = "Things",
        data = list(
            list(
                name = "Animals",
                y = 10,
                drilldown = "animals"
            )
        )
    ) %>%

    hc_drilldown(
        series = list(
            list(
                name = "Animals",
                id = "animals",
                data = list(
                    list(
                        name = "Cats",
                        y = 2,
                        drilldown = "cats"
                    )
                )
             ),
             list(
                 name = "Cats",
                 id = "cats",
                 data = list(list(name = "white cats", y = 2), list(name = "black cats", y = 3), list(name = "red cats",y = 4))
             )
         )
     )
hc
hc%
hc_图表(type=“column”)%>%
hc_xAxis(type=“category”)%%>%
hc_添加_系列(
name=“Things”,
数据=列表(
名单(
name=“动物”,
y=10,
向下钻取=“动物”
)
)
) %>%
hc_向下钻取(
系列=列表(
名单(
name=“动物”,
id=“动物”,
数据=列表(
名单(
name=“猫”,
y=2,
向下钻取=“猫”
)
)
),
名单(
name=“猫”,
id=“猫”,
数据=列表(列表(name=“白猫”,y=2)、列表(name=“黑猫”,y=3)、列表(name=“红猫”,y=4))
)
)
)
hc

如果需要多级向下展开,必须将向下展开的id设置为数据点,就像在纯js highcharts中一样

例如: 最重要的是:

drilldown: {
        series: [{
            id: 'animals',
            name: 'Animals',
            data: [{
                name: 'Cats',
                y: 4,
                drilldown: 'cats'
            }, ['Dogs', 2],
                ['Cows', 1],
                ['Sheep', 2],
                ['Pigs', 1]
            ]
        }, {

            id: 'cats',
            data: [1, 2, 3]
        }]
    }
您可以在这里看到,您的数据点不仅是数字,而且是包含链接到深入系列的对象

使用Highcharter的示例-简化,但您应该了解:

hc <- highchart() %>%
    hc_chart(type="column") %>%
    hc_xAxis(type="category") %>%
    hc_add_series(
        name = "Things",
        data = list(
            list(
                name = "Animals",
                y = 10,
                drilldown = "animals"
            )
        )
    ) %>%

    hc_drilldown(
        series = list(
            list(
                name = "Animals",
                id = "animals",
                data = list(
                    list(
                        name = "Cats",
                        y = 2,
                        drilldown = "cats"
                    )
                )
             ),
             list(
                 name = "Cats",
                 id = "cats",
                 data = list(list(name = "white cats", y = 2), list(name = "black cats", y = 3), list(name = "red cats",y = 4))
             )
         )
     )
hc
hc%
hc_图表(type=“column”)%>%
hc_xAxis(type=“category”)%%>%
hc_添加_系列(
name=“Things”,
数据=列表(
名单(
name=“动物”,
y=10,
向下钻取=“动物”
)
)
) %>%
hc_向下钻取(
系列=列表(
名单(
name=“动物”,
id=“动物”,
数据=列表(
名单(
name=“猫”,
y=2,
向下钻取=“猫”
)
)
),
名单(
name=“猫”,
id=“猫”,
数据=列表(列表(name=“白猫”,y=2)、列表(name=“黑猫”,y=3)、列表(name=“红猫”,y=4))
)
)
)
hc

这些深入调查的重要方面是关键。向下钻取的键是[name,value,drilldown]或[name,y,drilldown](因为它们主要是列向下钻取)

df = data_frame(name = dataframe$NAMES,
               y = dataframe$VALUES,
               drilldown = tolower(name))
所有引用的数据都应该具有相同的布局(除非最后一个没有打开到新数据集中的数据)。此布局应该是键的模式—名称、值和向下钻取id。向下钻取id用作向下钻取下一步的引用键

初始数据形成第一组列,下一组列有ID。下一组是第二层,第三组列有ID。第三组列形成第三层

示例:在宠物、鸟类和两栖动物的数据集中:宠物的下一层是猫、狗、仓鼠、鱼。宠物中的每个名字都有一个ID。猫会通过该ID拉入斑猫、棕色、黑色、汤姆。狗会从ID拉入斗牛犬、哈巴狗、实验室科基犬,仓鼠也是如此

#LAYER ONE OF DRILLDOWN
animalsdf = data_frame(name = animals$NAMES,
               y = animals$VALUES,
               drilldown = tolower(paste(name,'id')))

#Example of drilldown ID's here: 'pets id', 'birds id', 'amphibians id'

animalsds = list_parse(animalsdf)

names(animalsds) = NULL

#LAYER TWO OF DRILLDOWN
petsdf = data_frame(name = typeofpets$NAMES,
               y = typeofpets$VALUES,
               drilldown = tolower(paste(name,'id')))

birdsdf = data_frame(name = typeofbirds$NAMES,
               y = typeofbirds$VALUES,
               drilldown = tolower(paste(name,'id')))

amphibiansdf = data_frame(name = typeofamphibians$NAMES,
               y = typeofamphibians$VALUES,
               drilldown = tolower(paste(name,'id')))

petsds <- second_el_to_numeric(list_parse2(petsdf))
birdsds <- second_el_to_numeric(list_parse2(birdsdf))
amphibiansds <- second_el_to_numeric(list_parse2(amphibiansdf))

#LAYER THREE OF DRILLDOWN

#FOR PETS

catsdf = data_frame(name = typeofcats$NAMES,
               y = typeofcats$VALUES,
               drilldown = tolower(paste(name,'id')))

dogsdf= data_frame(name = typeofdogs$NAMES,
               y = typeofdogs$VALUES,
               drilldown = tolower(paste(name,'id')))

hamstersdf = data_frame(name = typeofhamsters$NAMES,
               y = typeofhamsters$VALUES,
               drilldown = tolower(paste(name,'id')))


catsds <- second_el_to_numeric(list_parse2(catsdf))
dogsds <- second_el_to_numeric(list_parse2(dogsdf))
hamstersds <- second_el_to_numeric(list_parse2(hamstersdf))

#FOR BIRDS
flightlessbirdsdf = data_frame(name = flightlessbirds$NAMES,
               y = flightlessbirds$VALUES,
               drilldown = tolower(paste(name,'id')))

flyingbirdsdf = data_frame(name = flyingbirds$NAMES,
               y = flyingbirds$VALUES,
               drilldown = tolower(paste(name,'id')))

flightlessbirdsds <- second_el_to_numeric(list_parse2(flightlessbirdsdf))
flyingbirdsds <- second_el_to_numeric(list_parse2(flyingbirdsdf))

#FOR AMPHIBIANS

largeamphibiansdf = data_frame(name = largeamphibians$NAMES,
               y = flyingbirds$VALUES,
               drilldown = tolower(paste(name,'id')))

smallamphibiansdf = data_frame(name = smallamphibians$NAMES,
               y = smallamphibians$VALUES,
               drilldown = tolower(paste(name,'id')))

largeamphibiansds <- second_el_to_numeric(list_parse2(largeamphibiansdf))
smallamphibiansds <- second_el_to_numeric(list_parse2(smallamphibiansdf))

#HIGHCHART STARTS

hc <- highchart() %>%
hc_chart(type = "column") %>% 
hc_title(text = "Drilldown") %>%
hc_subtitle(text = "XYZ") %>%
hc_xAxis(type = "category") %>%
hc_legend(enabled = FALSE) %>%
hc_plotOptions(
  series = list(
    boderWidth = 0,
    dataLabels = list(enabled = TRUE)
  )
) %>%
hc_add_series(
  name = "Category",
  colorByPoint = TRUE,
  data = animalsds
)  %>%
hc_drilldown(
  allowPointDrilldown = TRUE,
  series = list(
    list(
      id = "pets id",
      data = petsds,
      keys = list('name','y','drilldown')
    ),
    list(
      id = "birds id",
      data = birdsds,
      keys = list('name','y','drilldown')
    ),
    list(
      id = "amphibians id",
      data = amphibiansds,
      keys = list('name','y','drilldown')
    ),
    list(
      id = "cats id",
      data = catsds,
    ),
    list(
      id = "dogs id",
      data = dogsds
    ),
    list(
      id = "hamsters id",
      data = hamstersds
    ),
    list(
      id = "flightless birds id",
      data = flightlessbirdsds
    ),
    list(
      id = "flying birds id",
      data = flyingbirdsid
    ),
    list(
      id = "large amphibians id",
      data = largeamphibiansds
    ),
    list(
      id = "small amphibians id",
      data = smallamphibiansds
    )
)) %>% hc_tooltip(valueDecimals = 2)
#向下钻取的第一层
animalsdf=数据帧(name=动物$NAMES,
y=动物$value,
向下钻取=向下(粘贴(名称,'id'))
#这里有详细的ID示例:“宠物ID”、“鸟类ID”、“两栖动物ID”
animalsds=list_parse(animalsdf)
名称(animalsds)=空
#二层下钻
petsdf=数据帧(名称=类型页$名称,
y=typeofpets$值,
向下钻取=向下(粘贴(名称,'id'))
birdsdf=数据帧(名称=鸟的类型$名称,
y=鸟的类型$VALUES,
向下钻取=向下(粘贴(名称,'id'))
两栖动物DF=数据帧(名称=安菲比安的类型$名称,
y=安菲比安类型$值,
向下钻取=向下(粘贴(名称,'id'))

petsds这些深入分析的重要方面是关键。深入分析的关键是[name,value,drilldown]或[name,y,drilldown](因为它们主要是列深入分析

df = data_frame(name = dataframe$NAMES,
               y = dataframe$VALUES,
               drilldown = tolower(name))
所有引用的数据都应该具有相同的布局(除非最后一个没有打开到新数据集中的数据)。此布局应该是键的模式—名称、值和向下钻取id。向下钻取id用作向下钻取下一步的引用键

初始数据形成第一组列,下一组列有ID。下一组是第二层,第三组列有ID。第三组列形成第三层

示例:在宠物、鸟类和两栖动物的数据集中:宠物的下一层是猫、狗、仓鼠、鱼。宠物中的每个名字都有一个ID。猫会通过该ID拉入斑猫、棕色、黑色、汤姆。狗会从ID拉入斗牛犬、哈巴狗、实验室科基犬,仓鼠也是如此

#LAYER ONE OF DRILLDOWN
animalsdf = data_frame(name = animals$NAMES,
               y = animals$VALUES,
               drilldown = tolower(paste(name,'id')))

#Example of drilldown ID's here: 'pets id', 'birds id', 'amphibians id'

animalsds = list_parse(animalsdf)

names(animalsds) = NULL

#LAYER TWO OF DRILLDOWN
petsdf = data_frame(name = typeofpets$NAMES,
               y = typeofpets$VALUES,
               drilldown = tolower(paste(name,'id')))

birdsdf = data_frame(name = typeofbirds$NAMES,
               y = typeofbirds$VALUES,
               drilldown = tolower(paste(name,'id')))

amphibiansdf = data_frame(name = typeofamphibians$NAMES,
               y = typeofamphibians$VALUES,
               drilldown = tolower(paste(name,'id')))

petsds <- second_el_to_numeric(list_parse2(petsdf))
birdsds <- second_el_to_numeric(list_parse2(birdsdf))
amphibiansds <- second_el_to_numeric(list_parse2(amphibiansdf))

#LAYER THREE OF DRILLDOWN

#FOR PETS

catsdf = data_frame(name = typeofcats$NAMES,
               y = typeofcats$VALUES,
               drilldown = tolower(paste(name,'id')))

dogsdf= data_frame(name = typeofdogs$NAMES,
               y = typeofdogs$VALUES,
               drilldown = tolower(paste(name,'id')))

hamstersdf = data_frame(name = typeofhamsters$NAMES,
               y = typeofhamsters$VALUES,
               drilldown = tolower(paste(name,'id')))


catsds <- second_el_to_numeric(list_parse2(catsdf))
dogsds <- second_el_to_numeric(list_parse2(dogsdf))
hamstersds <- second_el_to_numeric(list_parse2(hamstersdf))

#FOR BIRDS
flightlessbirdsdf = data_frame(name = flightlessbirds$NAMES,
               y = flightlessbirds$VALUES,
               drilldown = tolower(paste(name,'id')))

flyingbirdsdf = data_frame(name = flyingbirds$NAMES,
               y = flyingbirds$VALUES,
               drilldown = tolower(paste(name,'id')))

flightlessbirdsds <- second_el_to_numeric(list_parse2(flightlessbirdsdf))
flyingbirdsds <- second_el_to_numeric(list_parse2(flyingbirdsdf))

#FOR AMPHIBIANS

largeamphibiansdf = data_frame(name = largeamphibians$NAMES,
               y = flyingbirds$VALUES,
               drilldown = tolower(paste(name,'id')))

smallamphibiansdf = data_frame(name = smallamphibians$NAMES,
               y = smallamphibians$VALUES,
               drilldown = tolower(paste(name,'id')))

largeamphibiansds <- second_el_to_numeric(list_parse2(largeamphibiansdf))
smallamphibiansds <- second_el_to_numeric(list_parse2(smallamphibiansdf))

#HIGHCHART STARTS

hc <- highchart() %>%
hc_chart(type = "column") %>% 
hc_title(text = "Drilldown") %>%
hc_subtitle(text = "XYZ") %>%
hc_xAxis(type = "category") %>%
hc_legend(enabled = FALSE) %>%
hc_plotOptions(
  series = list(
    boderWidth = 0,
    dataLabels = list(enabled = TRUE)
  )
) %>%
hc_add_series(
  name = "Category",
  colorByPoint = TRUE,
  data = animalsds
)  %>%
hc_drilldown(
  allowPointDrilldown = TRUE,
  series = list(
    list(
      id = "pets id",
      data = petsds,
      keys = list('name','y','drilldown')
    ),
    list(
      id = "birds id",
      data = birdsds,
      keys = list('name','y','drilldown')
    ),
    list(
      id = "amphibians id",
      data = amphibiansds,
      keys = list('name','y','drilldown')
    ),
    list(
      id = "cats id",
      data = catsds,
    ),
    list(
      id = "dogs id",
      data = dogsds
    ),
    list(
      id = "hamsters id",
      data = hamstersds
    ),
    list(
      id = "flightless birds id",
      data = flightlessbirdsds
    ),
    list(
      id = "flying birds id",
      data = flyingbirdsid
    ),
    list(
      id = "large amphibians id",
      data = largeamphibiansds
    ),
    list(
      id = "small amphibians id",
      data = smallamphibiansds
    )
)) %>% hc_tooltip(valueDecimals = 2)
#向下钻取的第一层
animalsdf=数据帧(name=动物$NAMES,
y=动物$value,