Log axis labels in ggplot2: full number without co

2019-08-04 00:12发布

Is there a way to show axis labels as a full number without a comma (and not in scientific format)? In the example below, I can get the labels to appear as full numbers with commas (e.g. 10,000), but I would like them without commas (e.g. 10000).

library(ggplot2)
library(scales)
df<-data.frame(x=c(10^(3:6)), y=c(10^(3:6)))
ggplot(df, aes(x=x, y=y))+geom_point()+scale_x_log10(labels=comma)+scale_y_log10(labels=comma)

标签: r ggplot2
1条回答
我命由我不由天
2楼-- · 2019-08-04 00:42

There may be a better way to do this, but I just looked at code of comma() (by typing the function name by itself) and wrote a new plain() function that doesn't use the big.mark="," argument:

plain <- function(x,...) {
   format(x, ..., scientific = FALSE, trim = TRUE)
}
ggplot(df, aes(x=x, y=y))+
 geom_point()+scale_x_log10(labels=plain)+scale_y_log10(labels=plain)
查看更多
登录 后发表回答