We present an economical model where an $S^{}_1$ leptoquark and an anomaly-free $U(1)^{}_X$ gauge symmetry with $X = B^{}_3-2L^{}_mu/3-L^{}_tau/3$ are introduced, to account for the muon anomalous magnetic moment $a^{}_mu equiv (g^{}_mu-2)$ and flavor puzzles including $R^{}_{K^{(ast)_{}}}$ and $R^{}_{D^{(ast)_{}}}$ anomalies together with quark and lepton flavor mixing. The $Z^prime_{}$ gauge boson associated with the $U(1)^{}_X$ symmetry is responsible for the $R^{}_{K^{(ast)_{}}}$ anomaly. Meanwhile, the specific flavor mixing patterns of quarks and leptons can be generated after the spontaneous breakdown of the $U(1)^{}_X$ gauge symmetry via the Froggatt-Nielsen mechanism. The $S^{}_1$ leptoquark which is also charged under the $U(1)^{}_X$ gauge symmetry can simultaneously explain the latest muon $(g-2)$ result and the $R^{}_{D^{(ast)_{}}}$ anomaly. In addition, we also discuss several other experimental constraints on our model.