gpt4 book ai didi

r - R图中的斜体希腊字母?

转载 作者:行者123 更新时间:2023-12-05 01:27:41 26 4
gpt4 key购买 nike

是否可以在 R 图中将希腊字母斜体化?理想情况下,以下代码将产生斜体希腊字母:

plot(1:10, 1:10, type="n")
text(8,4, expression(italic(gamma)~":"~italic(sigma))) #doesn't work...
text(2,2,expression(italic("this")~":"~italic("that")))

plotmath 文档非常清楚地说明 italic() 不适用于希腊字母,但是,他们确实说带有\uxxxxx 或\Uxxxxxxxx 的 UTF-8 可用于创建斜体希腊符号,但是我一直无法得到这个上类。有没有人对如何使用 utf 或其他方式执行此操作有任何建议?

可能有一些 Tex 解决方案,但我没有成功地让基本的 Tex 示例在我的系统上工作。我对他们持开放态度,但我可能会问一些后续问题。

下面的代码几乎绘制了我想要的,但不完全。
windows(family='serif') #name for Times in default windows gr device lib
plot(1:10, 1:10, type="n")
text(5,9, expression(italic(β)~":"~italic(α))) #1
text(5,7, paste("\u03B2",":","\u03B1",sep=" "), font=3) #2
text(5,5, expression(italic(beta)~":"~italic(alpha))) #3
text(5,3, expression(italic("\u03B2")~":"~italic("\u03B1"))) #4
text(5,1.5, expression(italic("\u03B2")~plain(":")~italic("\u03B1"))) #5

enter image description here

我需要斜体符号和非斜体“:”。在顶部 (#1) 中,斜体符号看起来很奇怪。在第二个中,斜体符号看起来正确,但“:”是斜体。是的,期刊编辑发现了这一点。

操作系统:Windows 7 x64

最佳答案

我在这个问题上挣扎。最终制作了一个数据结构以供将来使用,并在“正确的方式”上进行了一些搜索以制作 Unicode 字符(使用 paste0("\u", n) 以各种方式失败,我认为这是聪明的解决方法。

greeks <- 
structure(list(grsym = c("α", "β", "γ", "δ", "ε", "ζ",
"η", "θ", "ι", "κ", "λ", "μ", "ν", "ξ", "ο", "π", "ρ",
"ς", "σ", "τ", "υ", "φ", "χ", "ψ", "ω", "Α", "Β", "Γ",
"Δ", "Ε", "Ζ", "Η", "Θ", "Ι", "Κ", "Λ", "Μ", "Ν", "Ξ",
"Ο", "Π", "Ρ", "Σ", "Τ", "Υ", "Φ", "Χ", "Ψ", "Ω"),
decUTF = c(945, 946, 947, 948, 949, 950, 951, 952, 953, 954,
955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966,
967, 968, 969, 913, 914, 915, 916, 917, 918, 919, 920, 921,
922, 923, 924, 925, 926, 927, 928, 929, 931, 932, 933, 934,
935, 936, 937), hexUTF = structure(c(945L, 946L, 947L, 948L,
949L, 950L, 951L, 952L, 953L, 954L, 955L, 956L, 957L, 958L,
959L, 960L, 961L, 962L, 963L, 964L, 965L, 966L, 967L, 968L,
969L, 913L, 914L, 915L, 916L, 917L, 918L, 919L, 920L, 921L,
922L, 923L, 924L, 925L, 926L, 927L, 928L, 929L, 931L, 932L,
933L, 934L, 935L, 936L, 937L), class = "hexmode"), htmlSym = c("&alpha;",
"&beta;", "&gamma;", "&delta;", "&epsilon;", "&zeta;", "&eta;",
"&theta;", "&iota;", "&kappa;", "&lambda;", "&mu;", "&nu;",
"&xi;", "&omicron;", "&pi;", "&rho;", "&sigmaf;", "&sigma;",
"&tau;", "&upsilon;", "&phi;", "&chi;", "&psi;", "&omega;",
"&Alpha;", "&Beta;", "&Gamma;", "&Delta;", "&Epsilon;", "&Zeta;",
"&Eta;", "&Theta;", "&Iota;", "&Kappa;", "&Lambda;", "&Mu;",
"&Nu;", "&Xi;", "&Omicron;", "&Pi;", "&Rho;", "&Sigma;",
"&Tau;", "&Upsilon;", "&Phi;", "&Chi;", "&Psi;", "&Omega;"
), Description = c("GREEK SMALL LETTER ALPHA", "GREEK SMALL LETTER BETA",
"GREEK SMALL LETTER GAMMA", "GREEK SMALL LETTER DELTA", "GREEK SMALL LETTER EPSILON",
"GREEK SMALL LETTER ZETA", "GREEK SMALL LETTER ETA", "GREEK SMALL LETTER THETA",
"GREEK SMALL LETTER IOTA", "GREEK SMALL LETTER KAPPA", "GREEK SMALL LETTER LAMBDA",
"GREEK SMALL LETTER MU", "GREEK SMALL LETTER NU", "GREEK SMALL LETTER XI",
"GREEK SMALL LETTER OMICRON", "GREEK SMALL LETTER PI", "GREEK SMALL LETTER RHO",
"GREEK SMALL LETTER FINAL SIGMA", "GREEK SMALL LETTER SIGMA",
"GREEK SMALL LETTER TAU", "GREEK SMALL LETTER UPSILON", "GREEK SMALL LETTER PHI",
"GREEK SMALL LETTER CHI", "GREEK SMALL LETTER PSI", "GREEK SMALL LETTER OMEGA",
"GREEK CAPITAL LETTER ALPHA", "GREEK CAPITAL LETTER BETA",
"GREEK CAPITAL LETTER GAMMA", "GREEK CAPITAL LETTER DELTA",
"GREEK CAPITAL LETTER EPSILON", "GREEK CAPITAL LETTER ZETA",
"GREEK CAPITAL LETTER ETA", "GREEK CAPITAL LETTER THETA",
"GREEK CAPITAL LETTER IOTA", "GREEK CAPITAL LETTER KAPPA",
"GREEK CAPITAL LETTER LAMBDA", "GREEK CAPITAL LETTER MU",
"GREEK CAPITAL LETTER NU", "GREEK CAPITAL LETTER XI", "GREEK CAPITAL LETTER OMICRON",
"GREEK CAPITAL LETTER PI", "GREEK CAPITAL LETTER RHO", "GREEK CAPITAL LETTER SIGMA",
"GREEK CAPITAL LETTER TAU", "GREEK CAPITAL LETTER UPSILON",
"GREEK CAPITAL LETTER PHI", "GREEK CAPITAL LETTER CHI", "GREEK CAPITAL LETTER PSI",
"GREEK CAPITAL LETTER OMEGA")), .Names = c("grsym", "decUTF",
"hexUTF", "htmlSym", "Description"), row.names = c(NA, -49L), class = "data.frame")

这就是数据。 intToUtf8函数就是答案,我在 bquote 中实现了它战略:
start_e <- expression()   # Define the class of the expression vector.
plot(5,5)
text(2+(1:5),4, sapply( greeks[1:5,3],
function(x) c(start_e, bquote(italic(.(intToUtf8(x)))) ) ) )

这是在 Mac 上,因此这可能不是通用解决方案。这是我在我的设备上看到的:
png(width=480, height=200); plot(1:10, 1:10, type="n")
text(5,6, expression(italic(β)~":"~italic(α)))
text(5,3, expression(italic("\u03B2")~plain(":")~italic("\u03B1")) );dev.off()

enter image description here

关于r - R图中的斜体希腊字母?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25732949/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com