highcharter名义价值和百分比价值 [英] highcharter both nominal and percentage values
问题描述
我用高轮图书馆制作了一张饼图。
$ b
I've made a pie chart with the highcharter library.
library(highcharter)
test_data
Gender Freq colors
1 Female 29813 #ff99cc
2 Male 38474 #2980b9
hchart(test_data, "pie", hcaes(x = Gender, y = Freq, color=colors))
由于地图是交互式的,因此我希望饼图在同一图上显示百分比值和名义值 / strong>即可。
As the map is interactive, I want to have the pie chart showing both percentage values and nominal values on the same plot.
我有什么想法可以做到这一点?
Any ideas how I can do this?
推荐答案
您需要在工具提示选项中使用具有highcharter的JS()函数的格式化程序。此外,Highchart使用'this.point.percentage'来提供百分比。请确保不要在第一行末尾忘记%>%
。
You need to use a formatter with JS() function of highcharter, in the tooltip options. Moreover Highchart uses the 'this.point.percentage' to provide the percentages. Make sure not to forget the %>%
at the end of the first line.
诀窍:
This should do the trick for you:
hchart(test_data, "pie", hcaes(x = Gender, label=Gender,y = Freq, color=colors))%>%
hc_tooltip(formatter = JS ():{+ this.y +',百分比:'+ Highcharts.numberFormat(this。通过添加该行(再次使用magrittr''),使用HTML = FALSE)
%>%'是在行之前或之后):
hc_plotOptions(pie = list(dataLabels = list(enabled = TRUE,format ={point.label}:{point.y })))
by adding the line (again the magrittr '%>%' is needed before or after the line):
hc_plotOptions(pie =list(dataLabels = list(enabled = TRUE,format="{point.label}:{point.y}")))
您可以在标签上添加值或通过交换 {point.y}
与:
you can add on the labels the values or by exchanging the {point.y}
with the:
{point.percentage:.2f}%
,您可以添加百分比和标签(男,Felame)
{point.percentage:.2f}%
, you can add the percentage along with the label (Male,Felame)
这篇关于highcharter名义价值和百分比价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!