We calculate the leading order hadronic contribution to the muon anomalous magnetic moment using twisted mass lattice QCD. The pion masses range from 330 MeV to 650 MeV. We use two lattice spacings, a=0.079 fm and 0.063 fm, to study lattice artifacts. Finite-size effects are studied for two values of the pion mass, and we calculate the disconnected contributions for four ensembles. Particular attention is paid to the dominant contributions of the vector mesons, both phenomenologically and from our lattice calculation.