0

I have been trying to annotate text on individual facets in ggplot following the advice given on a similar Stackoverflow question. However, I continue to receive the error

Blockquote Error in $<-.data.frame(*tmp*, "PANEL", value = c(1L, 1L, 1L, 1L, : replacement has 108 rows, data has 3 Blockquote

Please find my data here.

The code for creating my graph is the following:

#read in data
 data<-read.csv("CTmax.csv")

#remove superfluent columns
 data<-subset(data, select = c(ID, Tank, Rate, Acc_time, Trial_time, CTmax, Age, SL))

#remove control from column "Rate"
 data<-data[!(data$Rate=="Control"),]

#change factor structure to numeric
data$Age <- as.numeric(as.character(data$Age))

#plot the trials
 plot_AM5<-ggplot(data,aes(x=SL,y=CTmax))+geom_point(aes(shape=Tank,size=1.5,colour=Rate))
 plot_AM5<-plot_AM5+theme(legend.position = c(0.9, 0.3), legend.background = element_rect(alpha("white", 0.5)))+
 guides(shape = guide_legend(override.aes = list(size = 4)),colour=guide_legend(override.aes = list(size = 4)))

 plot_AM5<-plot_AM5+facet_grid(~data$Age,scales="free_x")+coord_cartesian(xlim = c(4, 8))+guides(size=FALSE)
 plot_AM5<-plot_AM5 + scale_shape_manual(values = c(0, 1, 15,16))+ 
 scale_colour_manual(values = c("blue", "orange", "red"))+
 ylab(expression(paste(CT[max]," (",""*~degree*C, ")", sep="")))+
 xlab("Standard length (mm)")+theme_bw()

 plot_AM5<-plot_AM5+theme(strip.background = element_rect(colour="black", fill="white"))
 plot_AM5

When I now create a data.frame with the example text for each individual facet and try to plot it on the graph, I run into the above described error:

#plot text on individual facets
 ann_text <- data.frame(SL = c(7,7,5),CTmax = c(35,33,33),lab = c("Text1","Text2","Text3"),
                   Age = factor(c(7,14,21),levels = c("7","14","21")))

 plot_AM5<-plot_AM5 + geom_text(data = ann_text,label = "lab")
 plot_AM5

Has anybody an idea of what I am doing wrong? Thanks in advance!

Ademar
  • 1

0 Answers0