简体   繁体   English

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

[英]How to plot logarithm graph with R-plot?

I am trying to make the following graph with R-plot:我正在尝试使用 R-plot 制作以下图表:

在此处输入图片说明

I have the following code in R:我在 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)

The graph generated with the R-plot:用 R-plot 生成的图形:

在此处输入图片说明

How should I make my R graph look like the figure?我应该如何使我的 R 图看起来像图中的那样?

I'm not sure what it is you want to change in the figure, but here's a reasonable replica:我不确定你想在图中改变什么,但这里有一个合理的复制品:

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)
}

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM