为什么在R的persp3D图的坐标轴标签中,一些Unicode下标显示为矩形?

huangapple go评论96阅读模式
英文:

Why some unicode subscripts appear as rectangles in axes labels of persp3D in R?

问题

以下是翻译好的部分:

"I'd like to plot this persp3D with a z-axis label (zlab) that includes "art" and "2" as subscript.
With persp3D, "xlab, ylab, zlab titles for the axes must be character strings; expressions are not accepted"; therefore, I used unicodes, as suggested here.
However, the subscript "t" ("\u209C") and subscript "2" ("\u2082") are replaced by rectangles, surprisingly."

Data:

x <- c(4, 13.5555555555556, 23.1111111111111, 32.6666666666667, 42.2222222222222, 
51.7777777777778, 61.3333333333333, 70.8888888888889, 80.4444444444444, 
90)  
y <- c(340, 344.444444444444, 348.888888888889, 353.333333333333, 
357.777777777778, 362.222222222222, 366.666666666667, 371.111111111111, 
375.555555555556, 380)  
z <- structure(c(-0.0322313447424346, 0.0285984869688307, 0.0887786175071123, 
0.16315053227001, 0.23707067250712, 0.295511090896593, 0.347041501569685, 
0.406272829045792, 0.477401790172139, 0.554597402177076, -0.0408618465172623, 
0.0461728200953287, 0.102347139431252, 0.145375510047931, 0.187038818431414, 
0.226808247176202, 0.277320010159432, 0.338544933887537, 0.407313832540064, 
0.479861624170109, -0.0665649032100802, 0.0215397967370541, 0.0930584796535344, 
0.135250427917803, 0.153588043910132, 0.170031363460435, 0.206134484667028, 
0.256688005216006, 0.311531747422268, 0.368423006904619, -0.0257780437357965, 
0.050144568734309, 0.11354258394355, 0.141955971268351, 0.142183771057, 
0.141149564914805, 0.148191341986988, 0.164701867687502, 0.18690000323886, 
0.211928320228517, 0.106042749781278, 0.141651784681096, 0.162956565523642, 
0.158081721154576, 0.138570215528201, 0.119627888563561, 0.103125810236989, 
0.089213795470101, 0.0773629539419817, 0.0665481663909424, 0.247293191268696, 
0.234184673795509, 0.219203222343268, 0.194474482229333, 0.169630727954004, 
0.141150711654294, 0.104253225576039, 0.0702177561079657, 0.0441733194628657, 
0.0222312187522258, 0.334497158930934, 0.298706836979317, 0.271188556502483, 
0.264412988247681, 0.246811629808477, 0.217765481462091, 0.190266390882058, 
0.169388685218955, 0.154810446935317, 0.143414052229605, 0.316678207994894, 
0.301781511778714, 0.287073854085446, 0.300822065981404, 0.3107500705885, 
0.318149530390912, 0.328053757919202, 0.343099947424488, 0.359954369266852, 
0.377680459212135, 0.275321074040331, 0.271896370112909, 0.278465594804128, 
0.304742755170115, 0.357810501230542, 0.408155983970446, 0.458861330981766, 
0.512002065103596, 0.561983040571977, 0.610294657219977, 0.250520928783517, 
0.25736729590313, 0.26900454601623, 0.313356103865023, 0.379384255611503, 
0.456230669854048, 0.544731976789402, 0.620277571515017, 0.675202603394509, 
0.71960832120062), .Dim = c(10L, 10L))  

Code:

library(plot3D)
library(viridis)

zlab <- "\u0394\u2090\u1d63\u209C\u0070\u004F\u2082\u0028\u0020\u006B\u0050\u0061\u0029"; zlab
par(mfrow=c(1,1), mar=c(2,0,0,6), xpd=TRUE)
persp3D(x = x, y = y, z = z, border="black", resfac=0.5,
        lwd=0.3, xlim=c(0,90), ylim=c(340,380), zlim=c(-0.2,0.8), theta=-60, phi=5, bty = "g", expand = 0.9,
        ticktype="detailed", xlab="x", ylab="y", zlab=zlab, axes=TRUE, nticks=10, col=pl
英文:

I'd like to plot this persp3D with a z-axis label (zlab) that includes "art" and "2" as subscript.
With persp3D, "xlab, ylab, zlab titles for the axes must be character strings; expressions are not accepted"; therefore, I used unicodes, as suggested here.
However, the subscript "t" ("\u209C") and subscript "2" ("\u2082") are replaced by rectangles, surprisingly:

为什么在R的persp3D图的坐标轴标签中,一些Unicode下标显示为矩形?

Data:

x <- c(4, 13.5555555555556, 23.1111111111111, 32.6666666666667, 42.2222222222222, 
51.7777777777778, 61.3333333333333, 70.8888888888889, 80.4444444444444, 
90)  
y <- c(340, 344.444444444444, 348.888888888889, 353.333333333333, 
357.777777777778, 362.222222222222, 366.666666666667, 371.111111111111, 
375.555555555556, 380)  
z <- structure(c(-0.0322313447424346, 0.0285984869688307, 0.0887786175071123, 
0.16315053227001, 0.23707067250712, 0.295511090896593, 0.347041501569685, 
0.406272829045792, 0.477401790172139, 0.554597402177076, -0.0408618465172623, 
0.0461728200953287, 0.102347139431252, 0.145375510047931, 0.187038818431414, 
0.226808247176202, 0.277320010159432, 0.338544933887537, 0.407313832540064, 
0.479861624170109, -0.0665649032100802, 0.0215397967370541, 0.0930584796535344, 
0.135250427917803, 0.153588043910132, 0.170031363460435, 0.206134484667028, 
0.256688005216006, 0.311531747422268, 0.368423006904619, -0.0257780437357965, 
0.050144568734309, 0.11354258394355, 0.141955971268351, 0.142183771057, 
0.141149564914805, 0.148191341986988, 0.164701867687502, 0.18690000323886, 
0.211928320228517, 0.106042749781278, 0.141651784681096, 0.162956565523642, 
0.158081721154576, 0.138570215528201, 0.119627888563561, 0.103125810236989, 
0.089213795470101, 0.0773629539419817, 0.0665481663909424, 0.247293191268696, 
0.234184673795509, 0.219203222343268, 0.194474482229333, 0.169630727954004, 
0.141150711654294, 0.104253225576039, 0.0702177561079657, 0.0441733194628657, 
0.0222312187522258, 0.334497158930934, 0.298706836979317, 0.271188556502483, 
0.264412988247681, 0.246811629808477, 0.217765481462091, 0.190266390882058, 
0.169388685218955, 0.154810446935317, 0.143414052229605, 0.316678207994894, 
0.301781511778714, 0.287073854085446, 0.300822065981404, 0.3107500705885, 
0.318149530390912, 0.328053757919202, 0.343099947424488, 0.359954369266852, 
0.377680459212135, 0.275321074040331, 0.271896370112909, 0.278465594804128, 
0.304742755170115, 0.357810501230542, 0.408155983970446, 0.458861330981766, 
0.512002065103596, 0.561983040571977, 0.610294657219977, 0.250520928783517, 
0.25736729590313, 0.26900454601623, 0.313356103865023, 0.379384255611503, 
0.456230669854048, 0.544731976789402, 0.620277571515017, 0.675202603394509, 
0.71960832120062), .Dim = c(10L, 10L))  

Code:

library(plot3D)
library(viridis)

zlab <- "\u0394\u2090\u1d63\u209C\u0070\u004F\u2082\u0028\u0020\u006B\u0050\u0061\u0029"; zlab
par(mfrow=c(1,1), mar=c(2,0,0,6), xpd=TRUE)
persp3D(x = x, y = y, z = z, border="black", resfac=0.5,
        lwd=0.3, xlim=c(0,90), ylim=c(340,380), zlim=c(-0.2,0.8), theta=-60, phi=5, bty = "g", expand = 0.9,
        ticktype="detailed", xlab="x", ylab="y", zlab=zlab, axes=TRUE, nticks=10, col=plasma(100, begin=0.1, end=1),
        colkey = FALSE, cex.lab=2)  

Questions:

  1. What's the problem and how to fix it?
  2. Also, how to rotate it 180 degrees, as displayed on the plot below (which is what I would like but without using text3D)?

Note: I know that text3D is a good option to place precisely the axes labels, as used below; however, it has the tedious drawback of having to be re-adjusted each time the graph is rotated using theta and/or phi, which is why I don't want to use it.

par(mfrow=c(1,1), mar=c(2,0,0,6), xpd=TRUE)
persp3D(x = x, y = y, z = z, border="black", resfac=0.5,
        lwd=0.3, xlim=c(0,90), ylim=c(340,380), zlim=c(-0.2,0.8), theta=-60, phi=5, bty = "g", expand = 0.9,
        ticktype="detailed", xlab="x", ylab="y", zlab=NA, axes=TRUE, nticks=10, col=plasma(100, begin=0.1, end=1),
        colkey = FALSE, cex.lab=2)
text3D(0, 392, 0.4, expression(paste(Delta*""[art], "pO"[2], " (kPa)")), adj = 0.8, add = T, srt=92, cex=1.5)

为什么在R的persp3D图的坐标轴标签中,一些Unicode下标显示为矩形?
Thanks for help

答案1

得分: 0

看起来 par() 函数默认使用 Helvetica 字体,这是我本地 Windows 11 配置中没有的字体,也许这是问题的原因?

不管怎样,我在 par() 函数中将字体(family)更改如下("Microsoft Sans Serif",这是一种非常接近 "Helvetica" 的格式),解决了我未知 Unicode 的问题。
注意:加载 extrafonts 可以扩展不同字体的可能性:library(extrafont); extrafont::loadfonts("all")

不过,如何将这个 zlab 旋转 180 度(问题 2)?

代码:

library(plot3D)
library(viridis)
# library(extrafont); extrafont::loadfonts("all") # 可选

zlab <- "\u0394\u2090\u1d63\u209C\u0070\u004F\u2082\u0020\u0028\u006B\u0050\u0061\u0029"; zlab

windowsFonts(new_font = windowsFont("Microsoft Sans Serif"))

par(mfrow=c(1,1), mar=c(2,0,0,6), xpd=TRUE, family="new_font")
persp3D(x = x, y = y, z = z, border="black", resfac=0.5,
        lwd=0.3, xlim=c(0,90), ylim=c(340,380), zlim=c(-0.2,0.8), theta=-60, phi=5, bty = "g", expand = 0.9,
        ticktype="detailed", xlab="x", ylab="y", zlab=zlab, axes=TRUE, nticks=10, col=plasma(100, begin=0.1, end=1),
        colkey = FALSE, cex.lab=2)

为什么在R的persp3D图的坐标轴标签中,一些Unicode下标显示为矩形?

英文:

It seems that the par() function uses the Helvetica font by default, a font that I don't have on my locale Windows 11 configuration; maybe this is the cause of the problem?

Anyway, I changed the font (family) in the par() function as follows ("Microsoft Sans Serif", which is a format very close to "Helvetica"), and it solved my problem of unknown unicodes.
Note: loading extrafonts allows to extend possibilities of different fonts: library(extrafont); extrafont::loadfonts(&quot;all&quot;)

Nevertheless, how to rotate this zlab by 180 degrees (Question 2)?

Code:

library(plot3D)
library(viridis)
# library(extrafont); extrafont::loadfonts(&quot;all&quot;) # optional

zlab &lt;- &quot;\u0394\u2090\u1d63\u209C\u0070\u004F\u2082\u0020\u0028\u006B\u0050\u0061\u0029&quot;; zlab

windowsFonts(new_font = windowsFont(&quot;Microsoft Sans Serif&quot;))

par(mfrow=c(1,1), mar=c(2,0,0,6), xpd=TRUE, family=&quot;new_font&quot;)
    persp3D(x = x, y = y, z = z, border=&quot;black&quot;, resfac=0.5,
            lwd=0.3, xlim=c(0,90), ylim=c(340,380), zlim=c(-0.2,0.8), theta=-60, phi=5, bty = &quot;g&quot;, expand = 0.9,
            ticktype=&quot;detailed&quot;, xlab=&quot;x&quot;, ylab=&quot;y&quot;, zlab=zlab, axes=TRUE, nticks=10, col=plasma(100, begin=0.1, end=1),
            colkey = FALSE, cex.lab=2)

为什么在R的persp3D图的坐标轴标签中,一些Unicode下标显示为矩形?

huangapple
  • 本文由 发表于 2023年8月4日 04:27:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76831429.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定