作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
是否可以在 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")))
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
最佳答案
我在这个问题上挣扎。最终制作了一个数据结构以供将来使用,并在“正确的方式”上进行了一些搜索以制作 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("α",
"β", "γ", "δ", "ε", "ζ", "η",
"θ", "ι", "κ", "λ", "μ", "ν",
"ξ", "ο", "π", "ρ", "ς", "σ",
"τ", "υ", "φ", "χ", "ψ", "ω",
"Α", "Β", "Γ", "Δ", "Ε", "Ζ",
"Η", "Θ", "Ι", "Κ", "Λ", "Μ",
"Ν", "Ξ", "Ο", "Π", "Ρ", "Σ",
"Τ", "Υ", "Φ", "Χ", "Ψ", "Ω"
), 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)))) ) ) )
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()
关于r - R图中的斜体希腊字母?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25732949/
我有一个绘图脚本,我从 JSON 文件加载字幕(变量 subplot_titles): JSON 文件示例: "subplot_titles" : { "0" : "Model: $~w_{0
在 MATLAB 中,如果您在轴标签中键入“\alpha”,它将呈现“纯文本”希腊字符 alpha,而不需要 Latex。我希望对 Matplotlib 的 Pyplot 做同样的事情。 正在关注 H
我是一名优秀的程序员,十分优秀!