I am trying to create a bar chart for the recovery of a ICP MS machine. So I am having two vectors :
> number_matches
[1] 5.0 10.0 12.5 15.0 17.5 20.0 25.0 10.0 25.0 25.0 25.0
> iC_MW
[1] 4.808625427 9.073759209 11.058866657 12.916878917 14.974790823 16.515987287
[7] 20.721595708 0.006576491 0.040618454 20.031721743 20.885739448
My aim is to generate a barplot with paired bars from number_matches and iC_MW + the values of the iC_MW as numbes above the bar pair. I approached it this way:
recovery_frame_number<-as.matrix(number_matches)
recovery_frame_iC_MW<-as.matrix(iC_MW)
recovery_frame_merged <-cbind(recovery_frame_number,recovery_frame_iC_MW)
recovery_frame_merged<-t(recovery_frame_merged)
# Bar plot
ylim_number <- c(0, 1.1*max(number_matches))
ylim_iC_MW <- c(0, 1.1*max(iC_MW))
ylim_max <- as.numeric( max(ylim_iC_MW,ylim_number))
ylim_max <- c(0,ylim_max)
iC_MW<-round(iC_MW, 2)
bplot<-barplot(recovery_frame_merged, beside = T, col=c("red", "darkblue"), names.arg = number_matches, ylim = ylim_max)
text(x = number_matches, y = number_matches, labels = iC_MW)
I get the plot which I want to have, but I am having difficulties with the positioning of the labels. I tried different ways which I found in the net but usually my labels are positioned too near to each other and not at the correct places. For example see picture. If could give me a hint I would be very thankful. Thanks for reading and have a nice day :)
EDIT: Let me clarify that I am not using ggplot2 and I dont get the ggplot2 solution either working