5 Example Text with Code
Here is an example of a code chunk that creates a Log Scale.
plot(0,0,ty="n",xlim=c(0,10),ylim=c(0,3),xlab="Length along rule [inches]",ylab="",yaxt="n" ,
main="Making a Log Scale")
text(10*log10(c(1:10)),c(1:10)*0+2,c(1:10))
abline(h=1.4)
segments(10*log10(c(1:10)),1,10*log10(c(1:10)),1.8,lwd=2,col="blue")
segments(10*log10(seq(1,10,0.1 )),1.3, 10*log10(seq(1,10, 0.1)),1.5, lwd=1,col="blue")
segments(10*log10(seq(1,10,0.5 )),1.2, 10*log10(seq(1,10, 0.5)),1.6, lwd=2,col="blue")
segments(10*log10(seq(1, 2,0.2)),1.35,10*log10(seq(1, 2,0.2)),1.45,lwd=1,col="blue")
segments(10*log10(seq(1, 2,0.02)),1.37,10*log10(seq(1, 2,0.02)),1.43,lwd=1,col="blue")
text(2,2.5,"Logarithmic spacing:")
= c(1.13, 1.65,3.8,7.1,9.6)
Exmpls segments(10*log10(Exmpls),0.5,10*log10(Exmpls),1.3,lwd=1,col="red")
text(10*log10(Exmpls),0.3,as.character(Exmpls))
We can insert an image from a file like this:
We can also compute numbers and insert the results directly into the text. For example, suppose we want to initiate values for variables \(x\) and \(y\), and then compute and display within the text the result:
\[ z = \sqrt{x^2 + y^2}. \] (Note that the equation and its display is written in standard \(\LaTeX\) format.1)
= 55
x = 148
y = sqrt(x^2 + y^2) z
The final result for the variable \(z\) has a value of 157.89, rounded to two decimal places, which you see is directly embedded and appropriately displayed in the final text.