我正在尝试使用ggplot2创建一个像下面这张图片一样具有对数间隔网格的绘图。 我得到了等距离的网格,但不是对数间隔的。 我知道我缺少一些参数,但我现在似乎无法获得它。 我已经看到了许多关于这个主题的问题,如使用ggplot2创建对数正常刻度线(动态而非手动),但没有解决我正在寻找的问题。
set.seed(5)
x <- rlnorm(1000, meanlog=3.5, sdlog=1)
y <- rlnorm(1000, meanlog=4.0, sdlog=1)
d <- data.frame(x, y)
plot(x, y, log="xy", las=1)
grid(nx=NULL, ny=NULL, col= "blue", lty="dotted", equilogs=FALSE)
library(magicaxis)
magaxis(side=1:2, ratio=0.5, unlog=FALSE, labels=FALSE)
library(ggplot2)
library(MASS)
library(scales)
a <- ggplot(d, aes(x=x, y=y)) + geom_point() +
scale_x_log10(limits = c(1, NA),
labels = trans_format("log10", math_format(10^.x)),
breaks=trans_breaks("log10", function(x) 10^x, n=4)) +
scale_y_log10(limits = c(1, NA),
labels = trans_format("log10", math_format(10^.x)),
breaks=trans_breaks("log10", function(x) 10^x, n=4)) +
theme_bw() + theme(panel.grid.minor = element_line(color="blue", linetype="dotted"), panel.grid.major = element_line(color="blue", linetype="dotted"))
a + annotation_logticks(base = 10)
ggplot(d, aes(x, y))
。 - Ian Kent