2015-01-11 19 views
6

Göstergemde iki satır var. Bir satır kalın, renkli mavi ve büyük yazı tipini ve küçük yazı tipli bir çizgi, kırmızı ve italik olarak nasıl bir çizgi yapabilirim?r ggplot2: legend içinde değişen yazı tipi boyutları

library(ggplot2) 
library(gridExtra) 
p <- qplot(data = mtcars, wt, mpg) 
print(arrangeGrob(p, legend = 
    textGrob("large font size colour blue bold\n small font size colour red italic", 
      rot = -90, vjust = 1))) 

Yardımlarınız için teşekkür ederiz.

cevap

10

iki textGrob s metninizi bölmek gerekir:

library(ggplot2) 
library(gridExtra) 
p <- qplot(data = mtcars, wt, mpg) 
t1 <- textGrob("small font size colour red italic", 
       gp = gpar(fontsize = 12, col = 'red', fontface = 'italic'), 
       rot = -90, vjust = 1) 
t2 <- textGrob("large font size colour blue bold", 
       gp = gpar(fontsize = 20, col = 'blue', fontface = 'bold'), 
       rot = -90, vjust = 1) 
print(arrangeGrob(p, t1, t2, widths = c(9/10, 1/20, 1/20), nrow = 1)) 

enter image description here

4

expression ve atop kullanan bir çözüm:

p <- qplot(data = mtcars, wt, mpg) 
print(arrangeGrob(p, legend= 
     textGrob(expression(atop("large font size colour blue bold\n", atop(italic("small font size colour red italic")))), 
     rot = -90, vjust = 1, gp=gpar(fontsize=16,fontface="bold")))) 

enter image description here

+0

OP renk değiştirdi ihtiyacı çok. – hrbrmstr

+0

@hrbrmstr Üzgünüz, bunu özledim. Çözümümde farklı renkler eklemenin mümkün olmadığını düşünüyorum. – Jaap