在打印到pdf()

时间:2018-04-30 18:28:00

标签: r ggplot2

当使用pdf()时,我正努力在ggplot2中的绘图的轴标签上获得一个短划线。我正在使用MacOS High Sierra。

图表代码是:

fit1 <- lm(y ~ x, data.df)


 p1 <- ggplot(data.df, aes(x=x, y=y)) + 
  geom_point() +
  geom_abline(fit1, intercept = coef(fit1)[[1]], slope = coef(fit1) . 
 [[2]], color="red", size=.2) +
  xlab("CMP Left–Right Score")) +
  ylab("Disposition Towards BI")

如果我们这样做,这似乎正确呈现

quartz()
p1

但是,下面给出了一个连字符而不是一个短划线:

pdf(file="pooled.pdf", width=8, height=6)
p1
dev.off()

数据是:

structure(list(x = c(-16.667, -36.735, 43.243, -64.286, 37.963, 
-9.091, 6.593, -38.614, -30.496, -10.549, -45.455, -46.515, 25.926, 
-23.81, -29.53, -38.614, -4.478, 1.266, 1.176, -30.357, 5, 13.084, 
-7.692, -38.614, 14.62, 26.829, -13.725, -14.894, 24.299, 13.084, 
4.145, -13.433, 29.464, -1.049, -1.37, -38.168, 19.444, -5.882, 
14.516, -6.25, 9.756, -7.636, -24.742, -45.946, 7.813, -5.882, 
-19.931, -33.523, -20.556, -15.09, -36.432, -42.051, -15.108, 
-6.518, -25.472, -21.471, 13.75, -16.383, -11.384, -44.767, -16.771, 
0.472, -23.392, -27.715), y = c(-0.295492376, 0.187137648, 
-0.209073538, 
1.026732887, -0.524148543, 0.232093035, -1.617201837, -0.038851011, 
-0.351777544, 0.637192933, -0.783167803, 1.549387151, -0.742792721, 
-0.054633476, -2.204811412, 0.009461977, -0.594714182, 1.172333694, 
-0.951553793, 1.59911439, -1.246200649, -0.337551454, -2.631499836, 
0.6051641, -0.885991535, 1.492537342, -1.275241929, 1.658246706, 
-1.331133971, -0.676627085, -3.220241861, 0.82922329, -0.841711554, 
1.611623219, -1.531110402, 1.469424694, -1.979679497, -0.724442893, 
-3.523278033, 1.187782421, -0.842631246, 1.35252299, -1.950335, 
0.859798616, -2.152810527, -0.623310324, -3.48956421, 1.718330701, 
-0.809637545, 0.741273409, -1.96458669, 1.466255347, -2.675088542, 
-1.066556748, -3.436585287, 1.935368096, -0.870188157, 0.477034948, 
-2.49292584, 1.93375064, -2.924310472, -1.033098158, -3.250669464, 
2.086336567), party = c(1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 
6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 
3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 
8, 1, 2, 3, 4, 5, 6, 7, 8)), .Names = c("x", "y", "party"), row.names = 
c(NA, 
-64L), class = "data.frame")

1 个答案:

答案 0 :(得分:2)

开罗通常更善于处理字体,

library(ggplot2)

ggsave('en.pdf',ggplot() + xlab("hyphen-hyphen en–en em—em"),
       device = cairo_pdf)