R ggplot,两个刻度合在一起
我想缩放y轴:R ggplot,两个刻度合在一起,r,plot,ggplot2,scale,axis,R,Plot,Ggplot2,Scale,Axis,我想缩放y轴: 根据log10,我使用了: scale_y_log10(中断=传输中断(“log10”,函数(x)10^x)) 更多滴答声: 连续缩放(间隔=漂亮间隔(10)) 但从错误信息中,只能看到一个刻度。 有没有一种方法可以同时使用这两种刻度?如果我正确理解您的问题,您希望在对数刻度上有一个y轴,其刻度超过1、10、100等。下面是一个可重复的示例,描述您尝试的内容: library(ggplot2) library(scales) dat <- data.frame(X=1:3,
有没有一种方法可以同时使用这两种刻度?如果我正确理解您的问题,您希望在对数刻度上有一个y轴,其刻度超过1、10、100等。下面是一个可重复的示例,描述您尝试的内容:
library(ggplot2)
library(scales)
dat <- data.frame(X=1:3, Y=c(2,50,10000))
ggplot(data=dat, aes(x=X, y=Y)) + geom_point() +
scale_y_log10(breaks=trans_breaks("log10",function(x) 10^x)) +
scale_y_continuous(breaks=pretty_breaks(10))
## Error: Scale for 'y' is already present. Adding another scale for 'y', which will replace the existing scale.
也许很灵活,但很难看。您可以通过将结果应用于您的数据(dat$Y
在本例中),来探索trans_breaks在做什么。请注意,n
的值被视为建议而不是命令:
trans_breaks("log10", function(x) 10^x, n=2 )(dat$Y)
[1] 1 100 10000
trans_breaks("log10", function(x) 10^x, n=10)(dat$Y)
[1] 1.000 3.162 10.000 31.623 100.000 316.228 1000.000 3162.278 10000.000
或者您更喜欢1、3、10、30、100等形式的勾号。?如果是:
ggplot(data=dat, aes(x=X, y=Y)) + geom_point() +
scale_y_log10(breaks=c(1,3,10,30,100,300,1000,3000,10000))
我猜这些直接规格是你最好的选择。但如果您还需要任意y范围的灵活性,请从labels参数中获取提示并添加一个labels参数:
ggplot(data=dat, aes(x=X, y=Y)) + geom_point() +
scale_y_log10(breaks=trans_breaks("log10", function(x) 10^x, n=20),
labels=trans_format("log10", math_format(10^.x)))
如果我对你的问题理解正确,你希望在对数刻度上有一个y轴,而不仅仅是1、10、100等等。下面是一个重复的例子,描述了你的尝试:
library(ggplot2)
library(scales)
dat <- data.frame(X=1:3, Y=c(2,50,10000))
ggplot(data=dat, aes(x=X, y=Y)) + geom_point() +
scale_y_log10(breaks=trans_breaks("log10",function(x) 10^x)) +
scale_y_continuous(breaks=pretty_breaks(10))
## Error: Scale for 'y' is already present. Adding another scale for 'y', which will replace the existing scale.
也许很灵活,但很难看。您可以通过将结果应用于您的数据(dat$Y
在本例中),来探索trans_breaks在做什么。请注意,n
的值被视为建议而不是命令:
trans_breaks("log10", function(x) 10^x, n=2 )(dat$Y)
[1] 1 100 10000
trans_breaks("log10", function(x) 10^x, n=10)(dat$Y)
[1] 1.000 3.162 10.000 31.623 100.000 316.228 1000.000 3162.278 10000.000
或者您更喜欢1、3、10、30、100等形式的勾号。?如果是:
ggplot(data=dat, aes(x=X, y=Y)) + geom_point() +
scale_y_log10(breaks=c(1,3,10,30,100,300,1000,3000,10000))
我猜这些直接规格是你最好的选择。但如果您还需要任意y范围的灵活性,请从labels参数中获取提示并添加一个labels参数:
ggplot(data=dat, aes(x=X, y=Y)) + geom_point() +
scale_y_log10(breaks=trans_breaks("log10", function(x) 10^x, n=20),
labels=trans_format("log10", math_format(10^.x)))
听起来很混乱。你可能想考虑一下面子。相关:听起来令人困惑。你可能想考虑一下面子。相关的: