【问题标题】:Using UTF-8 codes for use in intToUtf8() in R?在 R 的 intToUtf8() 中使用 UTF-8 代码?
【发布时间】:2018-04-28 21:21:38
【问题描述】:

我正在尝试使用 UTF-8 代码将符号放在 R 图中的某些文本中。如果我想要一个黑色圆圈,我可以使用代码 intToUtf8(9679)。在哪里可以找到列出其他符号值的数据库?我想找到创建红色圆圈的代码(即 pch=16,col="red"),但我找不到特定符号的所有 unicode 值的列表。

# example R code
x <- 1:10
y1 <- rnorm(10, x*2, 0.5)
y2 <- rnorm(10, x, 0.5)
plot(x, y1, xlab='x-value', ylab='', pch=16)
points(x, y2, pch=16, col='red')
mtext(paste0('value for y1 (', intToUtf8(9679), ') and y2 (',    intToUtf8(9679), ')'), side=2, line=2)
# except that I want the second black circle in the axis label to be a red circle

感谢您的帮助, 米奇

【问题讨论】:

  • 你想创造传奇吗?如果是,请查看帮助页面:?legend。例如,legend("bottom", legend = c("y1", "y1"), col = c("black", "red"), pch = 16, ncol=2) 并不是最糟糕的。
  • 谢谢,但我宁愿只使用图例作为最后的选择。我希望在轴标签中包含信息,因为我的真实数据图没有图例的空间。
  • 查看 ?points() 以获取点字符 (pch) 和 how to do multi-colored labels 的列表。旁注:您可以使用\u25CF 而不是', intToUtf8(9679), 'large red circle 也有一个 unicode,但我怀疑你是否让它在情节中工作。
  • 谢谢@lukeA。我尝试了这些想法,我尝试了链接中的想法,但是在尝试将符号插入表达式命令时遇到问题:mtext(expression('value for y1 (\u25CF) and y2 ('* phantom('\u25CF') * ')'), side=2, line=2)。但我想知道你怎么知道黑点是\u25CF?是否有表格显示这些值是什么? ?points下没有那么多信息
  • 谢谢。我想我没有正确搜索。我仍然无法让它与红点的 unicode 一起使用。我最终遵循了multi-colored labels 提供的链接中的建议,但由于您不能同时使用phantom 命令和 unicode(因为 unicode 在expression 中被误解),所以我只是在其中放了一堆空格文本直到到达我想要的位置。

标签: r plot utf-8 colors pch


【解决方案1】:

这是我最终使用的解决方案。这不是最有效的,但它确实有效:

x <- 1:10
y1 <- rnorm(10, x*2, 0.5)
y2 <- rnorm(10, x, 0.5)
plot(x, y1, xlab='x-value', ylab='', pch=16)
points(x, y2, pch=16, col='red')
mtext('value for y1 (\u25CF) and y2 (  )', side=2, line=2)
mtext('                                   \u25CF', side=2, line=2, col='red')

# alternatively, the following would also work in place of line 6
mtext(paste0('value for y1 (', intToUtf8(9679),' and y2 (  )'), side=2, line=2)

如果您想为您的特定符号查找更多 unicode 字符信息,可以查看here

感谢 lukeA 在这方面的帮助。

【讨论】:

    猜你喜欢
    • 2015-08-03
    • 1970-01-01
    • 2011-09-11
    • 1970-01-01
    • 1970-01-01
    • 2015-06-05
    • 2021-03-22
    • 2013-03-22
    • 2019-02-02
    相关资源
    最近更新 更多