[R] superscript of plot 2 x-mean(x) vs. (x-xmean)^2 has part of the superscript 2 cutoff.

Sorkin, John j@ork|n @end|ng |rom @om@um@ry|@nd@edu
Sun Apr 10 23:40:36 CEST 2022



I am trying to produce two plots, one of x vs x^2 and the other x-mean(x) vs. (x-mean(x))^2 using base R functions. All works well EXCEPT for the superscript of the y axis of the second plot. Half of the superscript 2 in (x-mean(x))^2 is cut off. My code follows. Any suggestions for modification to the plot so that the superscript 2 will not be cut off would be apprecated.


x <- 0:100
xsq <- x^2
mydata1 <-data.frame(x=x,xsq=xsq)

oldpar <- par(mfrow=c(1,2),mfcol=c(1,2))

# First plot. This plot is fine.
plot(x,xsq,xlab="",ylab="",cex=0.5)
title(,xlab="x",ylab=expression(x^2))
abline(lm(xsq~x,data=mydata),col="red")
length(x)
length(xsq)
cor(x,xsq)
text(40, 8000, expression(Correlation == 0.97))

# Second Plot. Label of the y axis of this plot
# has the superscript 2 cut off.
xcentered <- x-mean(x)
xcenteredsq <- xcentered^2
plot(xcentered,xcenteredsq,xlab="",ylab="",cex=0.5)
# Superscipt of the y axis is cut off.
title(xlab="x-mean(x)",ylab=expression((x-mean(x))^2))
abline(lm(xcenteredsq~xcentered),col="red")
cor(xcentered,xcenteredsq)
text(0, 2000, expression(Correlation == 0.00))


Thank you,
John

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows


	[[alternative HTML version deleted]]



More information about the R-help mailing list