Suppose I have data where x, y, z are three different data generating methods, and the columns refer to beta_0, beta_1, beta_2, and beta_3. I want to convert this to tidy format and then plot the density of beta_0 in one plot (with 3 curves), ..., the density of beta_3 in one plot (with 3 curves), all four plots in one output plot (so in a 4x4 grid or 4x1 grid, whatever, possibly using facet_wrap?
My question is: what's the tidy format of this data, if it can be put in tidy format, and then the code to generate the four densities (with each plot having three density curves) using ggplot2?
Toy data (the "real" data has 200 observations for each method, not just 6):
x=matrix(c(4.790584, 2.654499, 1.3987716, 3.504921,
4.126791, 2.280143, 1.1348528, 3.084783,
4.555479, 2.226738, 1.7021107, 3.500337,
4.954719, 2.592864, 1.2658565, 4.213174,
3.608878, 2.059524, 0.5363011, 2.993644,
4.399778, 2.001757, 1.0602126, 3.377298), nrow=6, ncol=4, byrow=TRUE)
y=matrix(c(6.850924, 3.694619, 2.549025, 6.045664,
7.740951, 4.504154, 2.513180, 6.255492,
5.026915, 2.540771, 1.726427, 4.743082,
4.835503, 2.842332, 1.666898, 4.308631,
8.186425, 5.331871, 2.919130, 6.724499,
4.641722, 2.646673, 1.486447, 3.931251), nrow=6, ncol=4, byrow=TRUE)
z=matrix(c(4.651634, 2.611540, 1.5819549, 4.107449,
3.716444, 2.097695, 1.0136387, 3.051602,
4.184544, 1.986585, 1.0731731, 3.442379,
6.309591, 2.720760, 2.1551536, 4.572733,
6.614165, 3.253548, 2.6207540, 5.157300,
4.408838, 1.920230, 0.9850924, 3.320052), nrow=6, ncol=4, byrow=TRUE)
tidy=cbind(x, y, z)
question from:
https://stackoverflow.com/questions/65944385/convert-to-tidy-format-and-plot-four-density-plots-in-the-same-plot