![](/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.