Matt2014
Matt2014

Reputation: 23

R: make the text bold for the legend and the xlab & ylab parameters in a plot?

I must make all of the text in my plot bold.

I am plotting densities using this:

par(mfrow=c(1,1),family="serif")

plot(density(rxyTop30),col="green",lty=1,lwd=3,bty="l",main="",
xlab=expression(paste(R[xy])),xlim=c(0.0,0.5),ylim=c(0,12),font=2)
 lines(density(jfTop30),col="blue",lty=1,lwd=3)
  legend("topright",c(expression(paste(R[xy]," with 30 ancestors with most 
  progeny"),paste(beta," (",alpha," = 0.96",", ",beta, " = 8.031)"))),
  lwd=c(3,3),lty=c(1,1),col=c("green","blue"),bty="n")

I tried inserting font=2 in different places within the code. It only made the tick numbers bold on each axis.

Upvotes: 2

Views: 7252

Answers (2)

Jrakru56
Jrakru56

Reputation: 1321

a <- 2
b <- 5
plot(a,b)
legend("topleft", legend = c(as.expression(bquote(bold("Bold"))),
                             as.expression(bquote("Not Bold"))))

       

enter image description here

Upvotes: 2

user2352714
user2352714

Reputation: 356

The argument font controls the state of the tick numbers. If you want the axis labels to be bold you need the argument font.lab=2. I.e., the following code...

plot(density(rxyTop30),col="green",lty=1,lwd=3,font.lab=2,bty="l",main="",
xlab=expression(paste(R[xy])),xlim=c(0.0,0.5),ylim=c(0,12),font=2)
 lines(density(jfTop30),col="blue",lty=1,lwd=3)
  legend("topright",c(expression(paste(R[xy]," with 30 ancestors with most 
  progeny"),paste(beta," (",alpha," = 0.96",", ",beta, " = 8.031)"))),
  lwd=c(3,3),lty=c(1,1),col=c("green","blue"),bty="n")

Upvotes: 0

Related Questions