0

I am trying to save a plot created by ggplot in R and trying to save it in PNG8 format. But couldn't find out anywhere on how to save it in PNG 8 format. Could someone help me out? Here is what I have:

pdf("barplot1.pdf")
library(ggplot2)
days <- c("SAT", "SUN")
revenue <- c(100,150)
d <- data.frame(days = factor(c("SAT","SUN"), levels = c("SAT", "SUN")), revenue)
ggplot(data = d, aes(x=as.factor(days), y= revenue))+geom_bar(stat= "identity", fill= "blue")
dev.off()
hi15
  • 2,113
  • 6
  • 28
  • 51
  • 1
    If you do a find/replace on your code for "pdf" and replace with "png" everything should be fine. Though most people prefer using `ggsave` with ggplots... see `?ggsave`. – Gregor Thomas May 04 '15 at 22:33
  • but would that be in PNG-8 format? – hi15 May 04 '15 at 22:33
  • 3
    I just saved a PNG with `ggsave`, and looking at the file properties it says the bit depth is 8. So, yes! – Gregor Thomas May 04 '15 at 22:38
  • 2
    From `?png`: *png will normally use a palette if there are less than 256 colours on the page, and record a 24-bit RGB file otherwise* . Also see http://stackoverflow.com/questions/22707130/what-is-difference-between-png8-and-png24/22707268#22707268 – user20650 May 04 '15 at 22:41

0 Answers0