Number formatting axis labels in ggplot2?

前端 未结 3 623
后悔当初
后悔当初 2021-02-03 17:41

I\'m plotting a fairly simple chart using ggplot2 0.9.1.

x <- rnorm(100, mean=100, sd = 1) * 1000000
y <- rnorm(100, mean=100, sd = 1) * 1000000
df <- d         


        
3条回答
  •  温柔的废话
    2021-02-03 17:54

    More generally, you can control some nice parameters using the "scales" package. One of its functions is number_format().

    library(ggplot2)
    library(scales)
    p <- ggplot(mpg, aes(displ, cty)) + geom_point()
    

    For formatting your numbers, you can use the function number_format(). It offers some nice possibilities, such as controlling the number of decimals (here 2 decimals) and your decimal mark (here ',' instead of '.')

    p + scale_y_continuous(
      labels = scales::number_format(accuracy = 0.01,
                                     decimal.mark = ','))
    

提交回复
热议问题