在R中绘制对数刻度 [英] Plotting Log scale in R

查看:243
本文介绍了在R中绘制对数刻度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  plot.window中的错误我试图绘制一个对数刻度,但是我一直在得到这个错误:

(...):无效的log = 1 / h规范。

我不确定我做错了什么。下面是我的代码:

$ p $ #function
函数(stepsize,temp_val,counter){
while(计数器< 0){
计数器< - 计数器+步长
px_norm < - dnorm(计数器,平均值= 0,sd = .04)
temp_val < - temp_val + px_norm}
temp_val < - 2 * temp_val
temp_val < - temp_val *(stepsize / 2)
print(temp_val,digits = 12)
}

#初始步长
h < - .01
while(h> .00001){
x< - calc_error(h,0,-5)#给我一个结果。 5
err <-x-(exp( - 。02)* 0.5)
plot(1 / h,err,log =1 / h)
h < - h / 10}

基本上,在这个简短的函数中,我试图说明随着步长的增加,来自真实答案的错误将会减少。但是,我无法密谋这样做。任何帮助将不胜感激。谢谢

解决方案

这应该是创建剧情的一种简单方法:



< (h,函数(x)calc_error(x,0,-5) - (p,p) (1 / h,err,log =x)


I'm trying to plot a logarithmic scale, but I keep on getting this error:

Error in plot.window(...) : invalid "log=1/h" specification. 

I'm not sure what I am doing wrong. Below is my code:

   #function
function(stepsize, temp_val, counter) {
  while(counter < 0) {
    counter <- counter + stepsize
    px_norm <- dnorm(counter, mean = 0, sd = .04)
    temp_val <- temp_val + px_norm }
  temp_val <- 2*temp_val
  temp_val <- temp_val *(stepsize/2)
  print(temp_val, digits = 12)
}

#Initial step size
h <- .01 
while (h > .00001) {
  x <- calc_error(h, 0, -5) #Gives me a result around .5
  err <- x - (exp(-.02)*0.5)
  plot(1/h, err, log = "1/h")
  h <- h/10 }

Basically, in this short function I'm trying to show as the step size increases, the error from the real answer will decrease. However, I'm having trouble plotting this. Any help will be appreciated. Thanks

解决方案

This should be an easy way to create the plot:

h <- 10^-seq(2, 4)
err <- lapply(h, function(x) calc_error(x, 0, -5) - (exp(-.02) * .5))
plot(1/h, err, log = "x")

这篇关于在R中绘制对数刻度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆