export :: graph2office左右移动轴标签 [英] export::graph2office moves axis labels around

查看:116
本文介绍了export :: graph2office左右移动轴标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用ggplot2在R(RStudio)中进行了绘制.当我通过export::graph2office导出它们时,标签会四处移动.但是,只有在为标签指定字体时才会发生这种情况.

I have made plots in R (RStudio) with ggplot2. When I export them via export::graph2office, the labels are moved around. However, this only happens when I specify the font for the labels.

library (ggplot2)
library (export)    


plot_data <- data.frame (a = runif (1:20), b = seq (1:20))

x11 (width =  3, height = 3)

ggplot (data = plot_data, mapping = aes (x = a, y = b)) +
    geom_point () +
    labs (x = "my x-label", y = "my y-label") +
    theme (panel.background = element_blank(),
           panel.border = element_rect (fill = NA, size = 0.7),
               axis.ticks = element_line (color = "black", lineend = "round"),
               axis.ticks.length = unit (2, "mm"),
               axis.text = element_text (color = "black"),
               plot.margin = unit(rep (0, 4), "cm"),
                      text = element_text (size=18,  
                                family="ChantillyLH", 
                                color = "black")
               )

graph2office (file = "my_graph", type = "DOC")

在这里,您可以在R中看到图形(右侧),并在word中看到导出的图形(左侧):

Here, you can see the graph in R (to the right) and the exported graph in word (to the left):

在此示例中,对于y标签,不希望有的行为更加明显,但是x标签也被移动了一点.我想知道是否有办法解决这个问题.

The undesired behaviour is more obvious for the y-label in this example, but also the x-label is moved a bit. I wonder if there is a way to fix this.

当我指定另一个字体系列(例如family="Comic Sans MS":

The same happens when I specify another font family, for example family="Comic Sans MS":

甚至在没有给出text命令时也会发生:

it even happens when no textcommand is given:

推荐答案

答案可能是:是的,export::graph2office移动轴标签(export::graph2pptexport::graph2doc也是如此).无法解决此问题.如果要在R中对图形进行样式设置并将其原样导出到Office,则export::graph2office函数不是您的最佳选择.但是,该功能当然可以用作快捷选项,以生成可编辑的办公室图形.

The answer probably is: yes, export::graph2office moves axis labels around (so do export::graph2pptand export::graph2doc). There is no way to fix this. If you want to style your graphs in R and export them as-is into Office, the export::graph2office function, unfortunately, is not your way to go. However, the function can of course be used as a quick-and-dirty option to produce editable office-graphs.

如果您的目标是以更可靠的方式导出图形,则CairoSVG可能是一个更好的选择(请在此处查看我的答案:

If your goal is to export graphs in a more reliable manner, CairoSVG might be a much better option (see my answer here: Producing a vector graphics image (i.e. metafile) in R suitable for printing in Word 2007).

这篇关于export :: graph2office左右移动轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆