2015-05-03 7 views
10

Ecco la mia frame di dati:Difficoltà annotare trama quando i valori dell'asse x sono date

> s 
     Date Average Treatment  SE 
1 2014-10-15 4.875   1 1.6304852 
2 2014-11-12 6.250   1 0.9955257 
3 2014-12-11 0.250   1 0.1636634 
4 2015-02-11 1.000   1 0.5000000 
5 2015-03-09 0.000   1 0.0000000 
6 2014-10-15 22.750   2 3.4369318 
7 2014-11-12 10.625   2 2.1207942 
8 2014-12-11 7.500   2 2.9215945 
9 2015-02-11 7.750   2 2.3126207 
10 2015-03-09 0.125   2 0.1250000 

sto producendo un grafico utilizzando questo codice:

s$Date <- as.Date(s$Date) 
s$Treatment <- factor(s$Treatment) 
cols <- c("#000000","#F5F5DC") 
library(ggplot2) 
solitaryrecruits <- (ggplot(s, aes(x=Date, y=Average, fill=Treatment)) + 
    geom_bar(width=20, position=position_dodge(20), 
      stat="identity", colour="black") + 
    geom_errorbar(aes(ymin=Average, ymax=Average+SE), 
       width=10,      
       position=position_dodge(20))+ 
    scale_fill_manual(name="Treatment", labels=c("No Cage", "Cage"), values = cols) + 
    labs(x=("Panel Date"), y=expression(bold(paste("Mean Num. Ind. (" ,cm^2, ")", sep = "")))) + 
    theme_bw() + 
    theme(axis.text=element_text(size=14), 
     legend.title=element_text(size=14), 
     legend.text=element_text(size=12), 
     axis.title=element_text(size=16,face="bold"), 
     legend.justification = c(1, 1), legend.position = c(1, 1), 
     axis.title.x = element_text(vjust=-0.2), 
     axis.title.y = element_text(vjust=+0.6))) + 
    guides(fill = guide_legend(override.aes = list(colour = NULL))) + 
theme(legend.key = element_rect(colour = "black")) 

enter image description here

Ho diverse trame che presenterò a fianco a fianco. Pertanto, sto cercando di annotare ogni trama posizionando il testo (per questa trama "a)") nell'angolo in alto a sinistra. Ho provato a creare un livello di annotazione ma non riesco a specificare una posizione x. Qualsiasi aiuto sarebbe molto apprezzato, grazie!

Edit: ecco un foto modificata manualmente per mostrare quello che voglio mettere sulla trama:

enter image description here

risposta

9

È possibile utilizzare Annota per raggiungere il tuo obiettivo:

solitaryrecruits + 
    annotate(geom="text",x=as.Date("2014-10-05"), 
    y=25,label="a",fontface="bold") 

L'importante il punto è che tu dia la tua coordinata x come una data.

alternativa, si potrebbe etichettare le trame, dando loro un titolo

solitaryrecruits + labs(title="a") 
1

Si può fare in questo modo:

ggplot(s, aes(x=Date, y=Average, fill=Treatment)) + annotate("a)", 
x = as.POSIXct(-Inf, origin = '2014-10-15'), y = Inf, hjust = 1, vjust = 1) 
Problemi correlati