R plot()或ggplot2()中的对数y轴刻度标记 [英] Logarithmic y-axis Tick Marks in R plot() or ggplot2()
本文介绍了R plot()或ggplot2()中的对数y轴刻度标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 log =y
它有没有标签的简短的对数间隔小刻度标记,加上长的,对数间隔的带标签的主要刻度线。
有谁知道如何在 R
中实现这个功能?
解决方案
在基础R中,只需构建轴即可。
set.seed(5)
d< - data.frame(x = 1:100,y = rlnorm(100,meanlog = 5,sdlog = 3))
with(d,{
plot(x,y,log =y,yaxt =n )
y1 < - floor(log10(range(y)))
pow < - seq(y1 [1],y1 [2] +1)
ticksat< - as .vector(sapply(pow,function(p)(1:10)* 10 ^ p))
axis(2,10 ^ pow)
axis(2,ticksat,labels = NA,tcl = -0.25,lwd = 0,lwd.ticks = 1)
})
code> lattice , latticeExtra
包有以下功能:
<$ p $ (格)$ b $库库(latticeExtra)
xyplot(y〜x,data = d,scales = list(y = list(log = 10)),
yscale.components = yscale.components.log10ticks)
I saw the ideal tick-mark structure for a log="y"
plot in this paper, Figure 3b 3c 3d.
It has short, log-spaced minor tick marks without labels, plus long, log-spaced major tick marks with labels.
Does anyone know how to achieve this in R
?
解决方案
In base R just build the axes however you want. Something like this could be a start.
set.seed(5)
d <- data.frame(x=1:100, y=rlnorm(100, meanlog=5, sdlog=3))
with(d, {
plot(x, y, log="y", yaxt="n")
y1 <- floor(log10(range(y)))
pow <- seq(y1[1], y1[2]+1)
ticksat <- as.vector(sapply(pow, function(p) (1:10)*10^p))
axis(2, 10^pow)
axis(2, ticksat, labels=NA, tcl=-0.25, lwd=0, lwd.ticks=1)
})
In lattice
, the latticeExtra
package has the capability:
library(lattice)
library(latticeExtra)
xyplot(y~x, data=d, scales=list(y=list(log=10)),
yscale.components=yscale.components.log10ticks)
这篇关于R plot()或ggplot2()中的对数y轴刻度标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文