0

This is probably extremely simple but I cannot seem to find the answer. I am adding greek lettering to my legend (mu). However, when I do this the black outline around my legend key boxes does not appear when I use legend.key = element_rect(colour = "black"). I also want the legend key text to be bold but this also doesn't work.

Anyone got any tips?

Here is an example:

Example data (sorry, not sure how to upload it so imported from .csv):

Name,Time,Dose,Variable,n,Mean,SD,Median,Upper.SEM,Lower.SEM
Ted,1,0,P,3,20.1341,1.049791,20,0.5728394,0.5569923
Fred,1,0,P,3,38.63702,1.042969,37.74,0.9499892,0.9271918
Ted,1,1,P,3,22.79528,1.110182,21.64,1.4179833,1.334943
Fred,1,1,P,3,24.25966,1.156925,23.82,2.1300073,1.9580866

Example code:

R<- subset(example, Dose=="0")
S<- subset(example, Dose=="1")
R_S<- rbind(R,S)
names(R_S)

w<- ggplot(R_S, aes(x=Name, y=Mean,fill=interaction(Name,Dose) ))
w<-w + geom_bar(stat="identity", position="dodge") 
w<-w + geom_errorbar(aes(ymax=Mean+Upper.SEM, ymin=Mean-Lower.SEM),          position=position_dodge(0.9), width=0.5)
w<- w+   scale_fill_manual(values=c("#00FF00","#FF0000","#98FB98","#FF7F50"),name="",labels=c(~"Fred-    Control  (0"* mu * M* ")  ", ~"Ted- Control  (0"* mu * M* ")  ",~"Fred- Treated (1"* mu * M* ")  ",~"Ted- Treated (1"* mu * M* ")  "))
w + theme(legend.key = element_rect(colour = "black"))
w<-w+ theme(legend.position = "bottom") 
w<-w+ theme(legend.key.size = unit(1.5, "lines"))
w<- w + theme(legend.text = element_text(colour="black", size = 18, face = "bold"))
w<-w+ theme(axis.title.x = element_text( face="bold",size=20))
w<-w+ theme(axis.title.y = element_text(face="bold",size=20))
w<-w+ theme(axis.text.x=element_text(face="bold",colour='black', size=18))
w<-w+ theme(axis.text.y=element_text(face="bold",colour='black', size=16))
w
Henrik
  • 65,555
  • 14
  • 143
  • 159
MarinaWM
  • 79
  • 1
  • 4
  • possible duplicate of [How to make beta italic and bold in axis label and P italic and bold in text](http://stackoverflow.com/questions/24458090/how-to-make-beta-italic-and-bold-in-axis-label-and-p-italic-and-bold-in-text) – MrFlick Jul 02 '14 at 15:49

1 Answers1

1

This answer addresses the greek letter issue only.

As noted in ?plotmath:

Note that bold, italic and bolditalic do not apply to symbols, and hence not to the Greek symbols such as mu which are displayed in the symbol font.

and

In a UTF-8 locale any Unicode character can be entered, perhaps as a \uxxxx or \Uxxxxxxxx escape sequence, but the issue is whether the graphics device is able to display the character. The widest range of characters is likely to be available in the X11 device using cairo: see its help page for how installing additional fonts can help. This can often be used to display Greek letters in bold or italic.

So this works (depending on your device):

p <- ggplot(mtcars,aes(x = mpg,y = hp,color = factor(cyl))) + geom_point()
p + scale_color_manual(values = c('red','blue','green'),
                       labels = list(substitute(bold("\u03b2")),
                                     substitute(bold("\u03b1")),
                                     substitute(bold("\u03bc"))))
joran
  • 169,992
  • 32
  • 429
  • 468
  • `labels = expression(bold("\u03b2"), bold("\u03b1"), bold("\u03bc"))` is a bit easier on the keyboard. – baptiste Jul 05 '14 at 17:57