SORU
17 EYLÜL 2011, CUMARTESİ


Nasıl Ar-şeffaf arka plan ggplot2 kullanarak grafik yapmak için?

Şeffaf arka plan ile PNG dosyaları için R ggplot2 grafik çıktısına ihtiyacım var. Her şey temel R grafik, ama ggplot2: hayır şeffaflık ile ok

d <- rnorm(100) #generating random data

#this returns transparent png
png('tr_tst1.png',width=300,height=300,units="px",bg = "transparent")
boxplot(d)
dev.off()

df <- data.frame(y=d,x=1)
p <- ggplot(df)   stat_boxplot(aes(x = x,y=y)) 
p <- p   opts(
    panel.background = theme_rect(fill = "transparent",colour = NA), # or theme_blank()
    panel.grid.minor = theme_blank(), 
    panel.grid.major = theme_blank()
)
#returns white background
png('tr_tst2.png',width=300,height=300,units="px",bg = "transparent")
p
dev.off()

Ggplot2 ile şeffaf arka plan almak için herhangi bir yolu var mı?

CEVAP
17 EYLÜL 2011, CUMARTESİ


Ayrıca panel.background ek olarak plot.background bir seçenek daha var:

df <- data.frame(y=d,x=1)
p <- ggplot(df)   stat_boxplot(aes(x = x,y=y)) 
p <- p   opts(
    panel.background = theme_rect(fill = "transparent",colour = NA), # or theme_blank()
    panel.grid.minor = theme_blank(), 
    panel.grid.major = theme_blank(),
    plot.background = theme_rect(fill = "transparent",colour = NA)
)
#returns white background
png('tr_tst2.png',width=300,height=300,units="px",bg = "transparent")
print(p)
dev.off()

Nedense, yüklenen görüntüyü ihmal ettim bu yüzden benim bilgisayarda daha farklı gösteriliyor. Ama benim için, hala Beyaz olan tamamen gri bir arka plan ile bir arsa kutu grafiği kutu kısmı hariç. Bu dolgu, kutu grafiği, geom de estetik kullanılarak değiştirilebilir, inanıyorum.

Edit

ggplot2yana güncellendi ve opts() işlevi kalmıştır. Şu anda, opts() theme_rect(), vb yerine element_rect() yerine theme() kullanırsınız.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Flohoo

    Flohoo

    12 EYLÜL 2009
  • Jordie Jordan

    Jordie Jorda

    27 Ocak 2008
  • Michael Lummio

    Michael Lumm

    25 Mayıs 2007