**Update: Works in Rscript and when I run the entire chunk in Rmarkdown, but any idea as to why it doesnt work when I try to run the code line by line?
Hi there,
I am able to create a basic plot, but whenever I try to alter the x-axis labels I get the following error:
"Error in axis(1, seq(0, 1, 0.1)) : plot.new has not been called yet".
I would also like to label particular points on the plot (in particular, I would like the graph to label where a
and b
are on the graph.
a = 0.3 #lower bound of belief in theta
b = 0.8 #upper bound of belief in theta
A = 5 ## monetary value of harm from
x = c(seq(0,1,by=0.05))
expfine = function(x,A,a,b){ifelse(x<=a, A,
ifelse(a<x & x<b,(((b-x)/(b-a))*A),
ifelse(x>=b,0,NA)))}
expfine(x,A,a,b)
y = expfine(x,A,a,b)
plot(y ~ x,main = expression("Expected Fine given x"), xlab = expression("Level of Effort (x)"),ylab = expression("Expfine"), type = "l",col = "red")
axis(1,seq(0,1,0.1))
text(x = a, y = expfine(x=a,A,a,b),labels = "a")
text(x = b, y = expfine(x=b,A,a,b),labels = "b")
Any thoughts on where I am going wrong?