简体   繁体   English

绘图:R:图例定位(单位)+字体

[英]Plotting: R: Legend positioning (units) + font

I have the following 我有以下

xaxis <- seq(0,1,by=0.01)
aij <- sqrt(1 - (1-xaxis)**1.02)
bij <- 1 - (1 - xaxis)**1.50 
cij<-aij-bij
pdf("MyPdf.pdf",family="Times New Roman")
par(mfrow=c(1, 1), mar=c(5, 5, 4, 10))
plot(xaxis,aij,type="l", col="black",lty=1, xlab="Size ratio", ylab="Value of function")
lines(xaxis,bij,type="l",col="black",lty=2)
par(new=TRUE)
plot(xaxis,cij,,type="l",col="black",lty=4,xaxt="n",yaxt="n",xlab="",ylab="")
grid(nx = 10, ny = 10)
axis(4)
mtext("Difference", side=4,line=3)
legend(x='bottomright',col=c("black","black"), lty=c(1,2,3), legend=c("aij","bij","Difference"),inset=c(-0.25,0))
dev.off()

I am not able to understand the following: 我无法理解以下内容:

  1. How to specify the coordinates for the legend (for example instead of bottomright I wish to have a personally chosen position) - What are the units for the coordinate system and what is its orientation? 如何指定图例的坐标(例如,我希望自己选择一个位置而不是bottomright )-坐标系的单位是什么,其方向是什么?
  2. How to position the text properly? 如何正确放置文字?
  3. Is it possible to have BOLD, TIMES font in this plot for all the objects? 对于所有对象,此图中是否可以使用BOLD,TIMES字体?

This illustrates how to move the legend to a particular location in the coordinate system of the plot, with "user-coordinates". 这说明了如何使用“用户坐标”将图例移动到绘图坐标系中的特定位置。 See ?par for how to provide the proper value to 'text.font' in the ?legend function. 有关如何在?legend函数中为'text.font'提供适当值的信息,请参见?par My pdf-device has only a "Times" font, so I cannot show you how to use the named font you describe. 我的pdf设备只有一种“ Times”字体,因此我无法向您展示如何使用您描述的命名字体。 You can see the valid names of the currently available pdf fonts with: 您可以使用以下命令查看当前可用的pdf字体的有效名称:

names(pdfFonts())

pdf("MyPdf.pdf", family="Times")
par(mfrow=c(1, 1), mar=c(5, 5, 4, 10))
plot(xaxis,aij,type="l", col="black",lty=1, xlab="Size ratio", ylab="Value of function")
lines(xaxis,bij,type="l",col="black",lty=2)
par(new=TRUE)
plot(xaxis,cij,,type="l",col="black",lty=4,xaxt="n",yaxt="n",xlab="",ylab="")
grid(nx = 10, ny = 10)
axis(4)
mtext("Difference", side=4,line=3)
legend(x=0.2,y=0.02, col=c("black","black"), lty=c(1,2,3), legend=c("aij","bij","Difference"), text.font=2 )
dev.off()

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM