export :: graph2office左右移动轴标签 [英] export::graph2office moves axis labels around
问题描述
我用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 text
command is given:
推荐答案
答案可能是:是的,export::graph2office
移动轴标签(export::graph2ppt
和export::graph2doc
也是如此).无法解决此问题.如果要在R中对图形进行样式设置并将其原样导出到Office,则export::graph2office
函数不是您的最佳选择.但是,该功能当然可以用作快捷选项,以生成可编辑的办公室图形.
The answer probably is: yes, export::graph2office
moves axis labels around (so do export::graph2ppt
and 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屋!