简体   繁体   English

使用 ggsave() 保存时,线条覆盖在 ggplot2 bar plot 上

[英]Lines overlaid on ggplot2 bar plot when saved with ggsave()

When I view this bar plot in R Studio, it appears as I intended (this is from a screenshot):当我在 R Studio 中查看这个栏 plot 时,它显示为我想要的(这是来自屏幕截图): 预期情节

However, when I use the ggsave("filename.png") function, it appears with light-colored lines overlaid (may have to look closely to see):但是,当我使用ggsave("filename.png") function 时,它显示为覆盖有浅色线条(可能需要仔细观察才能看到):

已保存的带有重叠线的图

I'm using R version 3.2.3, ggplot2 version 2.00, and R Studio version 0.99.486, on OS X 10.11.3.我在 OS X 10.11.3 上使用R版本ggplot2版本 2.00 和 R Studio 版本 0.99.486。

Why might this be happening?为什么会这样?

You should check out the Cairo library. 你应该看看Cairo图书馆。 I use it for crisp graphics in presentations and reports. 我用它来演示和报告中的清晰图形。

Cairo initializes a new graphics device that uses the cairo graphics library for rendering. Cairo初始化了一个使用cairo图形库进行渲染的新图形设备。 The current implementation produces high-quality PNG, JPEG, TIFF bitmap files, high resolution PDF files with embedded fonts, SVG graphics and PostScript files. 当前的实现产生高质量的PNG,JPEG,TIFF位图文件,具有嵌入字体的高分辨率PDF文件,SVG图形和PostScript文件。 It also provides X11 and Windows interactive graphics devices. 它还提供X11和Windows交互式图形设备。 Unlike other devices it supports all graphics features including alpha blending, anti-aliasing etc. 与其他设备不同,它支持所有图形功能,包括alpha混合,抗锯齿等。

I can't reproduce your example, but here's a similar one. 我无法重现你的例子,但这里有类似的例子。

library("ggplot2")
pl <- ggplot(aggregate(mpg ~ cyl, mtcars, FUN=mean), 
             aes(x = cyl, y = mpg)) + 
       geom_bar(stat="identity", fill="red3") +
       theme_bw()

library("Cairo")
CairoPNG("CairoCarPlot.png")
pl
dev.off()

Uploading the PNG, it looks like: 上传PNG,它看起来像: 在此输入图像描述

Throwing this out there in case it helps anyone else.把它扔出去以防它对其他人有帮助。 I had this same issue when the stacked bar chart was made up of multiple values, I fixed it by grouping and then summarizing.当堆叠条形图由多个值组成时,我遇到了同样的问题,我通过分组然后汇总来修复它。 I think for your data it would be: df <- dataframe %>% group_by(Weekday) %>% summarize(percent=sum( percentage of tweets ))我认为对于您的数据,它将是:df <- dataframe %>% group_by(Weekday) %>% summarize(percent=sum( percentage of tweets ))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM