如何覆盖ggplot2的轴格式? [英] How to override ggplot2's axis formatting?

查看:171
本文介绍了如何覆盖ggplot2的轴格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当你选择一个对数标度时,ggplot2将格式化为10 ^ x。我希望它不这样做。例如,下面的代码应该显示一个图表,其中包括1,2,5等,而不是10 ^ 0,10 ^ 0.3,10 ^ 0.69等。

<$ p $ (x = 1:100,y = rlnorm(100))
中断< - as.vector(c) (1,2,5)%0%10 ^( - 1:1))
p1 < - ggplot(dfr,aes(x,y))+ geom_point()+ scale_y_log10(breaks = breaks)
print(p1)

我想添加一个 formatter code>参数指向 scale_y_log10 可以做到这一点,但我不确定应该在参数中输入什么,或者可以记录选项。

解决方案

scale_y_log10(breaks = breaks,labels = breaks / p>

When you choose a log scale, ggplot2 formats the breaks like 10^x. I'd like it to not do that. For example, the code below should display a graph with ticks at 1, 2, 5 etc, not 10^0, 10^0.3, 10^0.69 etc.

library(ggplot2)
dfr <- data.frame(x = 1:100, y = rlnorm(100))
breaks <- as.vector(c(1, 2, 5) %o% 10^(-1:1))
p1 <- ggplot(dfr, aes(x, y)) + geom_point() + scale_y_log10(breaks = breaks)
print(p1)

I guess that adding a formatter argument to scale_y_log10 would do the trick, but I'm not sure what to put in the argument, or where the options might be documented.

解决方案

scale_y_log10(breaks = breaks, labels = breaks should do the trick.

这篇关于如何覆盖ggplot2的轴格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆