r - ggplot2 中的 panel.border 在 Cairo PDF 设备的图的底部和右侧绘制粗线

标签 r ggplot2 cairo

enter image description here

我正在使用 Cairo 设置为

CairoPDF(file = "test2.pdf", width = 8.3, height = 11.7) 

主题设置是这样的:

mytheme<-theme_bw() +
         theme(plot.title = element_text(lineheight=.8, face="bold"),
               text=element_text(size=11, family="Times New Roman"))+ 
         theme(panel.border = element_rect(linetype = "dashed", 
                                           colour = "black"))+ 
         theme(plot.margin = unit(c(1,1.5,1,1.5), "inches"))

我想,这是我为 ggplot 设置的主题的问题。请给出修复它的建议。 谢谢。

最佳答案

仅使用 theme_bw() 我可以重现该功能。

df <- data.frame(lab = c('D1','D2','D3'),y = c(4,8,10),x= c(1,2,3))
library(Cairo)
#CairoPDF(file = "test2.pdf", width = 8.3, height = 11.7) 
library(grid)
library(ggplot2)
ggplot(df, aes(xmin = x-0.2, xmax = x + 0.2, ymin = 0, ymax = y,fill=lab)) +
  geom_rect()+xlim(labels = as.character(df$lab))+ theme_bw() 
dev.off()

当我们使用主题时,Cairo 和 ggplot2 的组合似乎会产生一些渲染问题。

一种解决方法是保存为简单的 pdf。我希望其他人使用这个可重现的示例给出更好的解决方案。

pdf(file = "test2.pdf", width = 8.3, height = 11.7) 

关于r - ggplot2 中的 panel.border 在 Cairo PDF 设备的图的底部和右侧绘制粗线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14563854/

相关文章:

r - ggtext : element_markdown not working with position = "top"

r - 如何在 geom_smooth 之后而不是在 geom_line 之后显示直接标签?

cairo - 在开罗绘制图像时如何禁用线性插值/平滑/抗锯齿?

R ggplot2 facet_wrap 中的 x 轴标签

r - 如何使用 unicode 箭头导出高分辨率 ggplot 图形

macos - 在pkg-config搜索路径中找不到包cairo

r - 为什么 'names' 的属性表现不同?

r - 是否可以停下来返回

r - 在 R 中生成报告

r - ggplot2::coord_cartesian 在方面