Let $P = (x, y)$ be a point in the plane; now if I want to rotate it by an angle $\theta$ the point $P$ will be moved from $(x, y)$ to $(X,Y)$ where:
$$X = x(\cos \theta) - y(\sin \theta)$$ $$Y = x(\sin \theta) + y(\cos \theta)$$
Why is this true, how can I represent it graphically? Can somebody explain me how to get the representative matrix of the rotation function?

For any linear transformation $T: V_1 \rightarrow V_2$, where $V_1$ and $V_2$ are vector spaces, its matrix representation consists of the images under $T$ of the basis vectors of $V_2$. Since $V_1 = \mathbb{R}^2$, we have that the matrix for a counterclockwise rotation of $\theta$ is
$$\left[\begin{array}{ll} \cos \theta & - \sin \theta \\ \sin \theta & \cos \theta \end{array}\right]$$