Снятие «Серии 1» в легенде и упорядочение легенды - PullRequest
0 голосов
/ 19 апреля 2020

Я создаю забавную кривую головоломки и хочу узнать следующее из того, как я написал код ниже:

Набор данных

Zone <- c('Overwhelm State', 'Overwhelm State', 'Puzzle Pairing State', 
  'Puzzle Pairing State', 'Puzzle Pairing State', 'Puzzle Pairing State', 
  'Puzzle Pairing State', 'Puzzle Pairing State', 'Puzzle Pairing State',
  '"I can do this" State', '"I can do this" State', '"I can do this" State',
  'Lost State','Lost State','Lost State','Lost State', 'Close Out State',
  'Close Out State', 'Close Out State','Close Out State', 'Close Out State', 
  'Close Out State')

`Jigsaw Puzzle Pieces`<- c(0.20, 0.10, 0.20, 0.40, 0.80, 1.60, 3.20, 
6.40, 12.80, 14.00,15.00, 18.00, 31.85, 33.50, 33.50, 31.85, 15.93, 
7.96, 3.98, 1.99, 1.00, 0.50)

Date <- as.Date(c('2020-03-28','2020-03-29','2020-03-30','2020-03-31',
  '2020-04-01','2020-04-02','2020-04-03','2020-04-04','2020-04-05','2020-04-06',    '2020-04-07','2020-04-08','2020-04-09','2020-04-10','2020-04-11','2020-04-12',
  '2020-04-13','2020-04-14','2020-04-15','2020-04-16','2020-04-17','2020-04-18'))

jigsaw_data <- data.frame(Date, `Jigsaw Puzzle Pieces`, Zone)

1) Как изменить размер шрифта заголовка?

2) Как убрать значение «Серия 1» из легенды, но сохранить линию, отображаемую на графике?

3) Как упорядочить легенду так, чтобы это:

"Overwhelm State"
"Puzzle Pairing State"
"I can do this" State
"Lost State"
"Close Out State"

Код ниже:

library(highcharter)
highchart() %>%
  hc_add_series(jigsaw_data, type = "line", lineWidth = 10,
               hcaes(x = Date, y = `Jigsaw Puzzle Pieces`)) %>%
  hc_add_series(jigsaw, type = "column",
               hcaes(x = Date, y = `Jigsaw Puzzle Pieces`, group = Zone)) %>%
  hc_xAxis(type = 'datetime', labels = list(format = '{value:%b %d}')) %>%
  hc_title(text = "<b>Jigsaw Puzzle Modelling Curve</b>") %>%
  hc_subtitle(text = "<b>COVID-19 Bias<b>") %>%
  hc_xAxis(title = list(text = '<b>Quarantine Period<b>',lineWidth = 3)) %>%
  hc_yAxis(title = list(text = '<b>Time Required to Insert One Puzzle Piece<b>')) %>%
  hc_legend(align = "right", verticalAlign = "top",
            layout = "vertical", x = 0, y = 100) 

enter image description here

Ответы [ 2 ]

1 голос
/ 20 апреля 2020
  1. Вы можете изменить размер шрифта заголовка, используя https://api.highcharts.com/highcharts/title.style

  2. Вы можете удалить первую серию из легенды, установив series.showInLegend: false https://api.highcharts.com/highcharts/series.line.showInLegend

  3. Вы можете расположить серию в легенде, используя series.legendIndex : https://api.highcharts.com/highcharts/series.line.legendIndex

Если вы хотите, чтобы я показал вам, как это сделать в вашем коде (я отредактирую ответ), то, пожалуйста, предоставьте весь код с данными , На данный момент, при попытке запустить ваш код путем копирования / вставки в RStudio, я получаю сообщение об ошибке " объект 'Jigsaw' не найден ".

edit : это это весь код. Мой путь не идеален (я использовал JavaScript, потому что я не знаю R), но он работает, как вы ожидали:

library(highcharter)
Zone <- c('Overwhelm State', 'Overwhelm State', 'Puzzle Pairing State', 
          'Puzzle Pairing State', 'Puzzle Pairing State', 'Puzzle Pairing State', 
          'Puzzle Pairing State', 'Puzzle Pairing State', 'Puzzle Pairing State',
          '"I can do this" State', '"I can do this" State', '"I can do this" State',
          'Lost State','Lost State','Lost State','Lost State', 'Close Out State',
          'Close Out State', 'Close Out State','Close Out State', 'Close Out State', 
          'Close Out State')

`Jigsaw Puzzle Pieces`<- c(0.20, 0.10, 0.20, 0.40, 0.80, 1.60, 3.20, 
                           6.40, 12.80, 14.00,15.00, 18.00, 31.85, 33.50, 33.50, 31.85, 15.93, 
                           7.96, 3.98, 1.99, 1.00, 0.50)

Date <- as.Date(c('2020-03-28','2020-03-29','2020-03-30','2020-03-31',
                  '2020-04-01','2020-04-02','2020-04-03','2020-04-04','2020-04-05','2020-04-06',    '2020-04-07','2020-04-08','2020-04-09','2020-04-10','2020-04-11','2020-04-12',
                  '2020-04-13','2020-04-14','2020-04-15','2020-04-16','2020-04-17','2020-04-18'))

jigsaw_data <- data.frame(Date, `Jigsaw Puzzle Pieces`, Zone)

highchart() %>%
  hc_add_series(jigsaw_data, type = "line", lineWidth = 10,
                hcaes(x = Date, y = `Jigsaw Puzzle Pieces`)) %>%
  hc_add_series(jigsaw_data, type = "column",
                hcaes(x = Date, y = `Jigsaw Puzzle Pieces`, group = Zone)) %>%
  hc_chart(events = list(load = JS("function() {

    this.series.forEach(function(series) {
      if (series.name === 'Series 1') {
        series.update({
          showInLegend: false
        });
      }
      if (series.name === '\"I can do this\" State') {
        series.update({
          legendIndex: 2
        });
      }
      if (series.name === 'Close Out State') {
        series.update({
          legendIndex: 4
        });
      }
      if (series.name === 'Lost State') {
        series.update({
          legendIndex: 3
        });
      }
      if (series.name === 'Overwhelm State') {
        series.update({
          legendIndex: 0
        });
      }
      if (series.name === 'Puzzle Pairing State') {
        series.update({
          legendIndex: 1
        });
      }
    });

  }"))) %>%
  hc_xAxis(type = 'datetime', labels = list(format = '{value:%b %d}')) %>%
  hc_title(text = "<b>Jigsaw Puzzle Modelling Curve</b>", style = list(fontSize = '30px')) %>%
  hc_subtitle(text = "<b>COVID-19 Bias<b>") %>%
  hc_xAxis(title = list(text = '<b>Quarantine Period<b>',lineWidth = 3)) %>%
  hc_yAxis(title = list(text = '<b>Time Required to Insert One Puzzle Piece<b>')) %>%
  hc_legend(align = "right", verticalAlign = "top",
            layout = "vertical", x = 0, y = 100) 
0 голосов
/ 20 апреля 2020

Для заголовка вы можете сделать это,

       `style: {
          fontSize: "14px"
        }`

Для удаления «серии 1» вы можете вставить showInLegend: false. API: https://api.highcharts.com/highcharts/plotOptions.series.showInLegend

       `series: [
        {
          type: "line",
          data: data,
          showInLegend: false, //this will hide the legend
        },...`

Для переупорядочения легенды, которую вы можете использовать, можно отсортировать, установив legendIndex для каждой серии. API: https://api.highcharts.com/highcharts/series.line.legendIndex

       `series: [
        {
          type: "line",
          data: data_1,
          name: "Overwhelm State",
          legendIndex: 1
        },
         {
          type: "line",
          data: data_2,
          name: "Puzzle Pairing State",
          legendIndex: 2
        },...`
...