[英]Convert r plot with log axis to log 2 axis
我有以下R代碼:
x <- readClipboard()
> plot(x)
> myData = x
> myResult = ecdf(myData)
> myResult
Empirical CDF
Call: ecdf(myData)
x[1:200] = -0.031027, -0.13797, -0.16993, ..., 0.016108, 0.60295
> plot(myResult, xlim=c(0,1e1), log="x")
這將導致基於日志的軸。 但是,x軸基於log 10。 如何將其轉換為以2為底的對數?
我嘗試了以下選項:在以下基礎上:
x <- 1:10
y <- 1:10
base <- 2
plot(x,y,axes=FALSE)
axis(1,at=x,labels = base^(x))
axis(2,at=y)
我做了:
base <- 2
> plot(myResult,y,axes=FALSE)
> plot(myResult,axes=FALSE)
> axis(1,at=x,labels = base^(x))
Error in base^(x) : non-numeric argument to binary operator
> axis(1,at=myResult,labels = base^(myResult))
Error in base^(myResult) : non-numeric argument to binary operator
我也沒有嘗試通過magicaxis做到這一點:
magaxis(magaxis(unlog='x'), powbase=2)
Error in axis(side = list(family = "sans"), at = c(-0.2, 0, 0.2, 0.4, :
invalid axis number -2147483648
> magaxis((unlog='x'), powbase=2)
Error in axis(side = "x", at = c(-0.2, 0, 0.2, 0.4, 0.6, 0.8, 1, 1.2), :
invalid axis number -2147483648
In addition: Warning message:
In axis(side = "x", at = c(-0.2, 0, 0.2, 0.4, 0.6, 0.8, 1, 1.2), :
NAs introduced by coercion
> plot(myResult)
> magaxis((unlog='x'), powbase=2)
Error in axis(side = "x", at = c(-0.2, 0, 0.2, 0.4, 0.6, 0.8, 1, 1.2), :
invalid axis number -2147483648
In addition: Warning message:
In axis(side = "x", at = c(-0.2, 0, 0.2, 0.4, 0.6, 0.8, 1, 1.2), :
NAs introduced by coercion
使用ggplot2
和scales
包會更容易。
ggplot(my_data, aes(x = VARX, y = VARY)) + geom_point() + scale_y_continuous(trans = log2_trans())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.