We propose a nonparametric Bayesian approach to estimate time-varying grouped patterns of heterogeneity in linear panel data models. Unlike the classical approach in Bonhomme and Manresa (Econometrica, 2015, 83, 1147-1184), our approach can accommodate selection of the optimal number of groups and model estimation jointly, and also be readily extended to quantify uncertainties in the estimated group structure. Our proposed approach performs well in Monte Carlo simulations. Using our approach, we successfully replicate the estimated relationship between income and democracy in Bonhomme and Manresa and the group characteristics when we use the same number of groups. Furthermore, we find that the optimal number of groups could depend on model specifications on heteroskedasticity and discuss ways to choose models in practice.