Search code examples
rnumber-formattingdecimal-point

R decimal comma instead of decimal point in ggplot scales::percent


I have been trying to get R to print a , instead of . in the percentage labels of my plot, but it doesn't work with any of the methods I found so far. I suspect that running

format(data, decimal.mark=",") or options(OutDec= ",") might not work because I am requesting the percentages to be printed from the label=scales::percent(Prozent/100). I have tried using some kind of paste(Prozent+"%") as a workaround, but the point remains. :(

plot <- ggplot(probleme, aes(x=reorder(Name, Häufigkeit), y= Häufigkeit, fill = mean)) +
          geom_col(position="dodge") +
          coord_flip() + 
          scale_fill_gradient(low = "#FEDFE8",  high = "#AC0634", limits=c(6,8), breaks = c(6,7,8))+
          scale_y_continuous(limits = c(0,1650), expand = c(0,0.1))+
          scale_x_discrete(expand = c(0,0)) + 
          geom_text(aes(label=scales::percent(Prozent/100)), 
                 position = position_dodge(0.5), hjust = -0.02, colour = "black", size=5)

Where in my code can I specify that I want a decimal comma? Any help would be appreciated :) Thanks


Solution

  • Add decimal.mark = "," to your geom_text() command to modify the comma symbol.

    geom_text(aes(label=scales::percent(Prozent/100,decimal.mark = ",")), 
                     position = position_dodge(0.5), hjust = -0.02, colour = "black", size=5)