[英]panel.border in ggplot2 ploting thicker lines in bottom and right side of the plot in CairoPDF device
I am using Cairo setting as 我正在使用开罗设置为
CairoPDF(file = "test2.pdf", width = 8.3, height = 11.7)
and theme setting is like this: 主题设置是这样的:
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"))
I guess, this is a problem with my theme setting for ggplot. 我想,这是我对ggplot设置主题的问题。 please give advice to fix it.
请提供建议以修复它。 Thanks.
谢谢。
Using only theme_bw()
I can reproduce the feature. 仅使用
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()
It seems that the combination of Cairo and ggplot2, when we use a theme, creates some rendering problems. 当我们使用主题时,Cairo和ggplot2的组合似乎会产生一些渲染问题。
One workaround is to save in simple pdf. 一种解决方法是将其保存为简单的pdf。 I hope that others give a better solution using this reproducible example.
我希望其他人可以使用此可复制示例提供更好的解决方案。
pdf(file = "test2.pdf", width = 8.3, height = 11.7)
This may or may not fix your specific problem, but I often have this issue with 'grid' objects with respect to the pixel scaling. 这可能会或可能不会解决您的特定问题,但是在像素缩放方面,我经常遇到“网格”对象的问题。 I can frequently fix the problem by slightly reducing or increasing the size of the image.
我可以通过稍微减小或增大图像的大小来经常解决此问题。
I would troubleshoot by taking the following steps: 我将通过以下步骤进行故障排除:
windows(width=8.3, height=11.7, xpinch=72, ypinch=72)
before you print the plot to screen. windows(width=8.3, height=11.7, xpinch=72, ypinch=72)
请确保使用以下格式获取像素之间的精确匹配: windows(width=8.3, height=11.7, xpinch=72, ypinch=72)
。 Good luck! 祝好运!
I have the same problem with bottom and right panel borders becoming thicker when sending the above ggplot example code to svg, pdf, cairo_pdf etc. 将上述ggplot示例代码发送到svg,pdf,cairo_pdf等时,底部和右侧面板的边框变粗,我也遇到同样的问题。
Here's a workaround that I use in Inkscape which might give some insight to someone with better understanding of R and pdf/svg rendering: 这是我在Inkscape中使用的一种解决方法,它可以使某些对R和pdf / svg渲染有更好理解的人有所了解:
In Inkscape: 在Inkscape中:
select the panel border 选择面板边框
object > ungroup (do this twice) 对象>取消分组(执行两次)
or keyboard shortcut shift+ctrl+G (x2) 或键盘快捷键shift + ctrl + G(x2)
So it seems the panel border is grouped with the panel background. 因此,似乎面板边框与面板背景分组在一起。 Surprisingly rather than the bottom and right becoming thinner, the top and left become thicker.
令人惊讶的是,底部和右侧没有变薄,而是顶部和左侧变粗了。 So actually it looks like OP question should be rephrased to "plotting thinner lines in top and left side of plot".
因此,实际上,OP问题应该改写为“在图的顶部和左侧绘制更细的线”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.