Win*_*der 0 r ggplot2 rstudio tidyverse
Complete noob to R/RStudio/tidyverse.
Using R 3.4.0 "You Stupid Darkness" / RStudio 1.0.136.
Trying to format y axis to display thousands to 1 decimal place.
I'm using :
scale_y_continuous(labels = scales::unit_format("k", 1e-3)) but displays as a whole number. How can I display 1 decimal place so instead of 30k, I get 30.1k?
Thx
如果您需要更灵活的功能,建议您使用自己的自定义函数并将其插入scale_y_continuous如下所示:
library(ggplot2)
# custom formatting function
scaleFUN <- function(x) sprintf("%.1fk", x/1000)
# setup diamonds dataset to display something in the thousands
diamonds2 <- diamonds
diamonds2$price <- diamonds2$price * 100
# make your plot and label using the custom scaleFUN function
ggplot(diamonds2, aes(x = carat, y = price)) +
geom_point() +
scale_y_continuous(name = 'Price ($K)',
labels = scaleFUN)
Run Code Online (Sandbox Code Playgroud)