使用scale_x_continuous()正确处理-Inf和Inf标签和点

Ric*_*tta 5 r ggplot2

我想用包含 Inf 和 -Inf 值的变量制作 gg 散点图:

myDF <- data.frame(ratio = log2(0:6/6:0), intensity = rep(1, 7))
Run Code Online (Sandbox Code Playgroud)

这是我的 ggplot 代码...

library(ggplot2)
p <- ggplot(myDF, aes(x = ratio, y = intensity)) +
       geom_point() 
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

...它可以毫无问题地处理 Inf 和 -Inf 点。不过,我有两个问题:

问题1

我如何访问标签?它们似乎超出了我可以访问的范围scale_x_continuous

P + scale_x_continuous(breaks = seq(-2.5, 2.5, 0.5))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

P + scale_x_continuous(breaks = seq(-5, 5, 1))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

问题2

如何避免 Inf 和 -Inf 点在绘图边缘被截断?我认为这是正确的方向,但还不完全正确:

p + scale_x_continuous(expand = c(0.3, 0.3))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述