How to change font family in this R plot? [duplicate]

久未见 提交于 2019-12-12 01:27:56

问题


I am trying to change the font of axis and legend to serif but adding family='serif' did not work for the legend. How should I do it?

plot(sort(n.cdf),pch=3,cex = 0.5,xlab="Order",ylab="Cn",family="serif")
par(new=TRUE)
plot(sort(emp.c),col="red",pch=1,cex = 0.5,ann=FALSE, axes=FALSE)
par(new=TRUE)
legend( "topleft"
         , inset = c(0,0.1) 
         , cex = 1
         , bty = "n"
         , legend = c("Simulated", "Empirical")
         , text.col = c("black", "red")
         , pt.bg = c("black", "red")
         , pch = c(3,1)
       , family=c("serif")
)

回答1:


Set the family plotting parameter before calling legend() to the value you want. Do this via an explicit call to par().

Here is an 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( ... )

## reset plotting parameters
par(op)


来源:https://stackoverflow.com/questions/29552772/how-to-change-font-family-in-this-r-plot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!