![](/img/trans.png)
[英]Setting panel.border in ggplot theme turns panel background white (wipes out the plot itself)
[英]panel.border in ggplot2 ploting thicker lines in bottom and right side of the plot in CairoPDF device
我正在使用开罗设置为
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)
这可能会或可能不会解决您的特定问题,但是在像素缩放方面,我经常遇到“网格”对象的问题。 我可以通过稍微减小或增大图像的大小来经常解决此问题。
我将通过以下步骤进行故障排除:
windows(width=8.3, height=11.7, xpinch=72, ypinch=72)
请确保使用以下格式获取像素之间的精确匹配: windows(width=8.3, height=11.7, xpinch=72, ypinch=72)
。 祝好运!
将上述ggplot示例代码发送到svg,pdf,cairo_pdf等时,底部和右侧面板的边框变粗,我也遇到同样的问题。
这是我在Inkscape中使用的一种解决方法,它可以使某些对R和pdf / svg渲染有更好理解的人有所了解:
在Inkscape中:
选择面板边框
对象>取消分组(执行两次)
或键盘快捷键shift + ctrl + G(x2)
因此,似乎面板边框与面板背景分组在一起。 令人惊讶的是,底部和右侧没有变薄,而是顶部和左侧变粗了。 因此,实际上,OP问题应该改写为“在图的顶部和左侧绘制更细的线”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.