Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change comma and thousand separator in tick labels

Tags:

r

plotly

In a chart like the one below I wan to change the thousand separator to a dot ".", but I don't know how to use the tickformat parameter in order to get it.

require(plotly)
p <- plot_ly(x=~c(2012,2013,2014,2015,2016), y=~c(1200000,975000,1420000,1175000,1360000), type='bar') %>%
     layout(yaxis = list(title="Income in €", tickformat=",d", gridcolor = "#bbb"), xaxis = list(title="Year"), margin=list(l=80))
p

enter image description here

like image 742
Alfredo Sánchez Avatar asked Apr 16 '17 10:04

Alfredo Sánchez


People also ask

How do you format a thousands separator?

The character used as the thousands separatorIn the United States, this character is a comma (,). In Germany, it is a period (.). Thus one thousand and twenty-five is displayed as 1,025 in the United States and 1.025 in Germany.

How do you add a thousand separator in Python?

Using the modern f-strings is, in my opinion, the most Pythonic solution to add commas as thousand-separators for all Python versions above 3.6: f'{1000000:,}' . The inner part within the curly brackets :, says to format the number and use commas as thousand separators.


1 Answers

As far as I know if you use tickformat, separators gets ignored. So you can either specify your tickformat or your separators.

require(plotly)
p <- plot_ly(x=~c(2012, 2013, 2014, 2015, 2016), y=~c(1200000, 975000, 1420000, 1175000, 1360000), type = 'bar') %>%
  layout(separators = '.,', 
         yaxis = list(title='Income in Euro'))
p

enter image description here

like image 145
Maximilian Peters Avatar answered Oct 11 '22 16:10

Maximilian Peters