Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ggplot shape=Unicode(例如像“u2198”或LaTeX\searrow这样的箭头)?_R_Ggplot2_Unicode_Fonts_Shapes - Fatal编程技术网

ggplot shape=Unicode(例如像“u2198”或LaTeX\searrow这样的箭头)?

ggplot shape=Unicode(例如像“u2198”或LaTeX\searrow这样的箭头)?,r,ggplot2,unicode,fonts,shapes,R,Ggplot2,Unicode,Fonts,Shapes,我想在ggplot2geom_point()中使用Unicode形状(特别是箭头,如↘, Unicode“\u2198”或LaTeX\searrow),如shape=“\u2198”中所示,不是默认字体。在中,“问题似乎在于字体。显然,基本默认字体不包含对这些特定字形的支持。现在,如何更改geom_point()的形状参数的字体?” 对于轴中的Unicode。text使用主题(axis.text.x=element\u text(family=“freeerif”),并对所有文本使用主题(tex

我想在
ggplot2
geom_point()
中使用Unicode形状(特别是箭头,如↘, Unicode“\u2198”或LaTeX\searrow),如
shape=“\u2198”
中所示,不是默认字体。在中,“问题似乎在于字体。显然,基本默认字体不包含对这些特定字形的支持。现在,如何更改geom_point()的形状参数的字体?”

对于
轴中的Unicode。text
使用
主题(axis.text.x=element\u text(family=“freeerif”)
,并对所有
文本使用
主题(text=element\u text(size=16,family=“Comic Sans MS”)
,但如何对
形状执行此操作

  • 对于
    形状
    ,是否有使用Unicode的通用解决方案?(我必须以某种方式使用
    cairo
    和/或字体
    family
    参数吗?)
  • 如果没有,是否还有其他箭头形状?(我对箭头形状和图示符的搜索结果(包括在中)为空。)
  • 在我的例子中,我需要一个ggplot2层,显示离散类别中时间点变化方向的定性预测

    例如:

    library(dplyr)
    library(ggplot2)
    
    d <- tibble(year = c(1, 1, 2, 2),
           policy = rep( c('policy 1', 'policy 2'), 2),
           prediction = c(NA, 'increase', 'decrease', NA),
           predictionUnicode = c(NA, '\u2197', '\u2198', NA))
    
    ggplot(d) + 
      geom_point(aes(x = year, y = policy, color = prediction), shape = "\u2198")
    

    看来
    shape
    参数确实是正确的方法,对吗

    我尝试将
    Sys.setenv(LANG=“en_US.UTF-8”)
    Sys.setenv(LANG=“Unicode”)
    设置为无效,但可能一些全局语言设置会影响
    形状

    非常感谢你的帮助

    注意:这些用于Unicode的解决方案没有图例,如果没有正确的字体将无法工作:

    要获得正确的字体,请执行以下操作:
  • 查找包含您要查找的Unicode字符的已安装字体。我觉得很有帮助

  • 将已安装的字体导入R


  • 使用
    shape=“\u2198”
    而不是
    \u8600
    。使用
    \u
    符号指定字符时,值必须为十六进制。8600是Unicode字符右下箭头的十进制值;十六进制值为2198。

    谢谢;我将问题编辑为引用“\u2198”,但这也不能用ggplot为我呈现。啊,事实上,那么问题可能是用于呈现标签的字体。您使用的任何字体都可能不包含U+2198(不是很多字体)。我将不得不留给更熟悉ggplot2字体用法的用户一个更完整的答案。有一些示例显示了设置字体系列的用法,这可能会有所帮助,不过首先您需要识别包含字符的已安装字体;这澄清了我的Unicode问题与ggplot2的字体使用有关。我编辑了这个例子,加入了
    theme\u gray(base\u family=“”)
    ,但运气不好。我反复研究了一下这个问题,最终得出了相同的结论,特别是“R中的字体支持通常不是很好”。通过安装extrafont包()您可能会有所进展,但主要问题似乎是设置用于geom_point的字体。我尝试了很多不同的方法,包括
    theme\u set
    等等,但都没能成功。对不起:-(
    ggplot(d) + 
      geom_tile( aes(x = year, y = policy), color = "black", fill = "white") +   
      # geom_point does not allow new fonts?
      geom_point(aes(x = year, y = policy, 
                     color = prediction), shape = "\u2198") + 
      # geom_text does allow new fonts, but the legend text is fixed to "a"
      geom_text(aes(x = year, y= policy, 
                    color = prediction,
                    label = predictionUnicode), 
                family = "Calibri") + 
      scale_x_continuous(breaks = c(1,2)) +
      theme_gray(base_family = "Calibri") 
    
    library(extrafont)
    font_import()
    fonts()
    
    sessionInfo()
    R version 3.5.2 (2018-12-20)
    Platform: x86_64-apple-darwin15.6.0 (64-bit)
    Running under: macOS Mojave 10.14.3