I have a graph use the base graphics package. For the labels on specific points I use
text(i, MSSAcar$summary[i,7]+.7, qld$LGA[i],
col='red', cex=.7, family='serif')
I have also used this in the plot for main titles and axis labels. They all come out as expected.
When I add a legend I cannot seem to be able to set the font family.
Can anyone help please.
Thanks.
To change the legend size of the plot, the user needs to use the cex argument of the legend function and specify its value with the user requirement, the values of cex greater than 1 will increase the legend size in the plot and the value of cex less than 1 will decrease the size of the legend in the plot.
Go to the menu in RStudio and click on Tools and then Global Options. Select the Appearance tab on the left. Again buried in the middle of things is the font size. Change this to 14 or 16 to start with and see what it looks like.
You'll see the default font device "Helvetica".
Set the family
plotting parameter before calling legend()
to the value you want. Do this via an explicit call to par()
. Here is a simple example
x <- y <- 1:10
plot(x, y, type = "n")
text(x = 5, y = 5, labels = "foo", family = "serif")
## set the font family to "serif"
## saving defaults in `op`
op <- par(family = "serif")
## plot legend as usual
legend("topright", legend = "foo legend", pch = 1, bty = "n")
## reset plotting parameters
par(op)
Really, you could change family
before you do the first call to plot()
and leave out the family = "serif"
argument in the call to text()
. Setting via par()
is global for the current device, using parameters within function calls is local to that call.
The above code produces:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With