尽管不使用Highcharts
库,您仍可以执行类似的操作。
library(tidyverse)
library(ggforce)
library(scales)
library(ggplot2)
# -------------------------------------------------------------------------
A <- c("a","b","c","d")
B <- c(4,6,9,2)
C <- c(23,26,13,15)
df <- data.frame(A,B,C)
# Ensure A is a factor (we'll be using it to fill the pie)
df$A <- factor(df$A)
# compute the individual proportion in this case using var C
df$prop <- df$C/sum(df$C)
# compute the cumulative proportion and use that to plot ymax
df$p_end <- cumsum(df$prop)
# generate a y-min between 0 and 1 less value than p_end (using p_end)
df$p_start <- c(0,head(df$p_end,-1))
# -------------------------------------------------------------------------
# plot
df %>%
mutate_at(c("p_start","p_end"),rescale,to=pi*c(-.5,.5),from=0:1) %>%
ggplot +
geom_arc_bar(aes(x0 = 0,y0 = 0,r0 = .5,r = 1,start = p_start,end = p_end,fill=A)) +
coord_fixed() +xlab("X_label") + ylab("Y_lablel") + guides(fill=guide_legend(title="Legend Title"))
输出
希望有帮助。
,
尝试在startAngle = -90,endAngle = 90
内添加hc_add_series_labels_values
。
不建议使用警告hc_add_series_labels_values
,因此建议使用hc_add_series
。
highchart() %>%
hc_add_series(type = "pie",data = df,hcaes(x = A,y = B),startAngle = -90,endAngle = 90) %>%
hc_tooltip(pointFormat = '<b>{point.percentage:.1f}%</b>') %>%
hc_title(text = "ABC",margin = 20,style = list(color = "#144746",useHTML = TRUE))
本文链接:https://www.f2er.com/3168177.html