【问题标题】:Parliament graph with r-highcharter带有 r-highcharter 的议会图
【发布时间】:2020-04-07 05:16:41
【问题描述】:

谁能告诉我为什么这个图形不是用 R 绘制的?我有一些发生这种情况的图形,但我没有找到解决方案。它显示像棒棒糖图...

提前谢谢..

library(highcharter)

    name <- c('A','B')
    y <- c(40,60)
    color <- c('#4185F3','#427CDD')
    label <- c('A1','B1')

    parliament <- data.frame(name, y, color, label)

highchart() %>%
    hc_chart(type='item') %>%
    hc_title(text='Highcharts item chart') %>%
    hc_subtitle(text='Parliament visualization') %>%
    hc_plotOptions(series=list(dataLabels=list(enabled = TRUE,  format='{point.label}'),center=c('50%', '88%'),startAngle=-100,endAngle=100)) %>%
    hc_legend(labelFormat='{name} <span style="opacity: 0.4">{y}</span>') %>%
    hc_add_series(data=parliament,name='Representatives',keys=c('name', 'y', 'color', 'label')) %>%
    hc_tooltip(enabled=FALSE) %>%
    hc_credits(enabled = TRUE, text = "Plataforma SegmentaNet",href = "https://segmentanet.com", target="_blank") %>%
    hc_exporting(enabled = TRUE)

【问题讨论】:

  • 您的预期输出是什么?看起来你的图表准确地显示了你给它的东西。 y = 40 处的一个数据点和 y = 60 处的另一个数据点。
  • 我期待这样的图表(只有两方,60-40)highcharts.com/demo/parliament-chart
  • 您自己找到解决方案了吗?我遇到了同样的问题。

标签: r r-highcharter


【解决方案1】:

现在,它运行正常...

    name = c('Mixto','EH-Bildu','EAJ-PNV', 'C\'s', 'Plural', 'ERC', 'UP', 'VOX' , 'PP', 'PSOE')
  y= c(9, 5, 6, 10, 12, 13, 35, 52, 87, 120)
  label=c('Mixto','EH-Bildu','EAJ-PNV', 'C\'s', 'Plural', 'ERC', 'UP', 'VOX' , 'PP', 'PSOE')
  color=c("silver","#a3c93f","#1f813d","#ed5d19", "lightgreen", "#fce549", "#673165", "#66bc29", "#00a0e1", "#e30613")
  
  data <- data.frame(name, y, label, color)
  
  highchart() %>%
      hc_chart(type = "item") %>%
      hc_title(text = 'Highcharts item chart') %>%
      hc_subtitle(text = 'Parliament visualization') %>%
      hc_legend(enable = TRUE, labelFormat = '{name} <span style="opacity: 0.4">{y}</span>') %>%
      hc_add_series(
          name = 'Spanish Parliament',
          data = data,
          keys = c('name', 'y', 'label', 'color'),
          dataLabels = list(enabled = TRUE, format = '{point.label}'),
          startAngle = -100,
          endAngle = 100,
          #center = c('50%', '88%'),
          size = '80%')

sessionInfo()

Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=Spanish_Spain.1252  LC_CTYPE=Spanish_Spain.1252   
[3] LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C                  
[5] LC_TIME=Spanish_Spain.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] highcharter_0.8.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6        pillar_1.5.1      compiler_4.0.4    xts_0.12.1       
 [5] tools_4.0.4       digest_0.6.27     jsonlite_1.7.2    lubridate_1.7.10 
 [9] evaluate_0.14     lifecycle_1.0.0   tibble_3.1.0      lattice_0.20-41  
[13] pkgconfig_2.0.3   rlang_0.4.10      igraph_1.2.6      DBI_1.1.1        
[17] curl_4.3          yaml_2.2.1        xfun_0.22         stringr_1.4.0    
[21] dplyr_1.0.5       knitr_1.31        generics_0.1.0    vctrs_0.3.6      
[25] htmlwidgets_1.5.3 grid_4.0.4        tidyselect_1.1.0  data.table_1.14.0
[29] glue_1.4.2        R6_2.5.0          fansi_0.4.2       rmarkdown_2.7    
[33] TTR_0.24.2        purrr_0.3.4       tidyr_1.1.3       magrittr_2.0.1   
[37] backports_1.2.1   ellipsis_0.3.1    htmltools_0.5.1.1 rlist_0.4.6.1    
[41] rsconnect_0.8.16  assertthat_0.2.1  quantmod_0.4.18   utf8_1.2.1       
[45] stringi_1.5.3     broom_0.7.5       crayon_1.4.1      zoo_1.8-9 

问候

【讨论】:

    猜你喜欢
    • 2018-01-13
    • 1970-01-01
    • 2019-05-26
    • 1970-01-01
    • 2017-04-14
    • 1970-01-01
    • 2018-06-04
    • 2020-07-01
    • 2020-02-14
    相关资源
    最近更新 更多