data(favorite_bars)data(favorite_pies)highchart() %>%## Datahc_add_series( favorite_pies,"column",hcaes(x = pie,y = percent ),name ="Pie" ) %>%hc_add_series( favorite_bars,"pie",hcaes(name = bar,y = percent ),name ="Bars" ) %>%## Options for each type of serieshc_plotOptions(series =list(showInLegend =FALSE,pointFormat ="{point.y}%",colorByPoint =TRUE ),pie =list(center =c("30%", "10%"),size =120,dataLabels =list(enabled =FALSE) ) ) %>%## Axishc_yAxis(title =list(text ="percentage of tastiness"),labels =list(format ="{value}%"),max =100 ) %>%hc_xAxis(categories = favorite_pies$pie ) %>%## Titles, subtitle, caption and creditshc_title(text ="How I Met Your Mother: Pie Chart Bar Graph" ) %>%hc_subtitle(text ="This is a bar graph describing my favorite pies including a pie chart describing my favorite bars" ) %>%hc_caption(text ="The values represented are in percentage of tastiness and awesomeness." ) %>%hc_credits(enabled =TRUE, text ="Source: HIMYM",href ="https://www.youtube.com/watch?v=f_J8QU1m0Ng",style =list(fontSize ="12px") ) %>%hc_size(height =600 )
set.seed(123)df <-tibble(x =runif(10), y =runif(10), z =runif(10), name =paste("cat", 1:10))hchart( df,"bubble",hcaes(x = x, y = y),## showInLegend = TRUE,name ="You can move the points",cursor ="move",dragDrop =list(draggableX =TRUE,draggableY =TRUE )) %>%hc_add_dependency("modules/draggable-points.js")
回归线
代码
data(penguins, package ="palmerpenguins")penguins <- penguins[complete.cases(penguins), ]hchart( penguins,"scatter",hcaes(x = flipper_length_mm, y = bill_length_mm, group = species),regression =TRUE) %>%hc_colors(c("#d35400", "#2980b9", "#2ecc71")) %>%hc_add_dependency("plugins/highcharts-regression.js")
分区颜色
代码
library(dplyr)set.seed(123)n <-200colors <-sample(viridisLite::cividis(5, end = .9))df <-tibble(x =1:n,y =abs(arima.sim(n = n, model =list(ar =c(0.9)))) +2,y2 =10+ y,col =rep(colors, each = n /10, length.out = n))hchart(df, "coloredarea", hcaes(x, y, segmentColor = col)) %>%hc_add_series(df, "coloredline", hcaes(x, y2, segmentColor = col)) %>%hc_add_dependency("plugins/multicolor_series.js")