How to make a log posterior contour plot for 2 parameters in R?

Hi,

Suppose I have 3 variables, x, y, log posterior. x and y correspond to the x and y axes in the plot below. I am wondering how to make this plot, when there can be multiple combinations of x and y with different log posterior.

This plot is saved from Stan User’s Guide.

I tried geom_contour_filled(), but the contours may not be smooth. Any idea?