如何用 R-plot 绘制对数图?

How to plot logarithm graph with R-plot?

我正在尝试使用 R-plot 绘制以下图表:

我在 R 中有以下代码:

x = 0:8
f = log2(x)
plot(x, f, main="Função Logarítmica", xlab="X - Abscissas", ylab="Y - Ordenadas", t='l', ylim=c(-3,3), xlim=c(0,8), col=4, axes=F) 
axis(1, pos=0, at=seq(from=0, to=8, by=0.2))
axis(2, pos=0)   
# Inclui linhas de grade
abline(h=seq(-3,3,0.5),v=seq(-3,8,0.5),lty=3,col="gray", lwd=2)

用 R-plot 生成的图形:

我应该如何使我的 R 图表看起来像下图?

我不确定你想在图中更改什么,但这是一个合理的副本:

x = seq(0.1, 8, 0.1)
f = log2(x)
plot(x, f, main = "Função Exponencial", 
     xlab = "X - Abscissas", ylab = "Y - Ordenadas", t = 'n', 
     ylim= c(-3, 3), xlim = c(0, 8), col = 4, axes = FALSE) 

polygon(x = c(0, 8, 8, 0), y = c(-3, -3, 3, 3), col= "#e3e9ff")
abline(h = seq(-3, 3, 0.1), v = seq(-3, 8, 0.1), col = "white", lwd = 2)
lines(x, f, lwd = 2, col = "red3")
axis(1, pos = 0, at = 0:8)
axis(2, pos = 0) 
text(label = c("\u215b", "\u00bc", "\u00bd"),
     c(0.125, 0.25, 0.5), c(0.2, -0.2, -0.2), cex = 1.3)

for(i in seq(-3, 3)) {
  lines(c(0, 2^i, 2^i), c(i, i, 0), lty = 2)
  points(2^i, i, pch = 16, cex = 1.5)
}