I've tried to searching online how to align my equation properly, but it still looks like right aligned rather than all the equal signs are aligned, can you help? The below is my code in rmarkdown.
$$
\begin{aligned}
l(\theta_1,\theta_2,\sigma^2)
=-\frac{1}{2}nlog(2\pi)-nlog\sigma-\frac{1}{2\sigma^2}\sum_{i=1}^{n}(y_i-\mu)^2\\
=-\frac{1}{2}nlog(2\pi)-nlog\sigma-\frac{1}{2\sigma^2}\sum_{i=1}^{n}(y_i-\frac{\theta_1x_i}{\theta_2+x_i})^2
\end{aligned}
$$
And the result looks to be right aligned rather than all the equal signs are aligned (see below).
Result