问题
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.
回答1:
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:
来源:https://stackoverflow.com/questions/7136990/how-to-change-font-family-in-a-legend-in-an-r-plot