2

I'm a consultant working on a very large project to produce hundreds of visualizations about various companies using R. To map the visualizations to their locations in a report we're automating, I need to annotate the visualizations I produce by including a very small unique identifier in the bottom right hand corner of the image (outside the plot area). I've tried several annotate functions and played with the gridExtra package, but annotate would never end up in the right place, while gridExtra broke the loop I had set up. Here's the code I currently have running:

dataRaw<-read.csv("dataMaster.csv")
data1<-dataRaw[dataRaw$metric_name_official=="Projects on Budget",]
data2<-data1[data1$valueType=="actual value",]
peers<-unique(data2$companyPeerGroup)
data2$peerGroup<-for (i in peers){
  peerData<-subset(data2, companyPeerGroup==i)
  agencies<-unique(peerData$companyAbbr)
  for (i in companies){
    peerData$spotlightCompany<-i
    peerData$compName<-paste("Peer", peerData$companyCode)
    peerData$companyAbbr<-as.character(peerData$companyAbbr)
    peerData$spotlightCompany<-as.character(peerData$spotlightCompany)
    peerData$compName<-as.character(peerData$compName)
    peerData$compName[peerData$spotlightCompany==peerData$companyAbbr]<-       peerData$spotlightCompany[peerData$spotlightCompany==peerData$companyAbbr]
    ggplot(peerData, aes(x=timeframe, y=value, group=compName))+
      geom_line(color="dark gray", size=1, group=peerData$compName)+
      geom_line(data=peerData[peerData$compName==peerData$spotlightCompany,],      aes(x=timeframe, y=value), color="red", label=peerData$value, size=2,  group=peerData$compName)+
      scale_y_continuous(limits=c(0,1))+
      theme_classic(base_size = 12, base_family = "Helvetica")+
      ggtitle(paste(peerData$spotlightCompany, "Projects on Budget", sep=": "))+
      geom_point() 
   ggsave(paste(paste("C:/Users/jtexnl/", i, sep=""), "png", sep="."))
}
}

Anyway, that's my problem in a nutshell. Any suggestion on how I could get a small bit of text in the bottom right-hand corner of the images this produces? If you'd suggest a gridExtra solution, what would that look like in this code? My attempts to do that ended up breaking the loop, but then again I'm not very well-versed in using gridExtra.

Thanks!

John

user3626301
  • 101
  • 1
  • 3

0 Answers0