I am experimenting with R highcharter package to create a bar chart function. the code is as below. I request help in 1-How to change the format of the dataLabels to percentage ? 2-How to set X-axis label display angle. I want to set it to 45 degrees
hcbar_categorycount_vertical <- function(data=x,var=y){
df <- data.frame(prop.table(table(data[var])))
names(df) <- c(var,'Proportion')
df$Proportion <- round(df$Proportion*100,2)
df <- df%>% arrange(-Proportion)
df[,1] <- as.character(df[,1])
df[,1] <- factor(df[,1], levels = df[,1])
df$Cumulative <- round(cumsum(df$Proportion),2)
highchart(debug = TRUE) %>%
hc_xAxis(categories=df[[1]]) %>%
hc_yAxis(labels = list(format = "{value}%"), max = 100) %>%
hc_add_series(name=var,data=df$Proportion,type = "column",dataLabels = list(enabled = TRUE, format='{point.label}%'))
}
I am not sure what should be the syntax of "format" within dataLabel property list.The above code does not seem to work. I already referred to the highcharter vignette and this site : http://jkunst.com/highcharter/highcharts-api.html#hc_xaxis-and-hc_yaxis
But could not find an answer. Thanks for the help in advance.
@jeganathan-velu,
1) Try changing the '{point.label}%'
by '{point.y}%'
2) See the highcharts example. You need to add to the hc_xAxis
the argument labels = list(rotation = 90)
highcharter package is just the wrapper of highcharts so you can check all the examples and the well documented API from highcharts. Replicating highcharts demos
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With