library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   4.0.0     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.1.0     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(purrrfect)

Attaching package: 'purrrfect'

The following objects are masked from 'package:base':

    replicate, tabulate
library(patchwork)

(sim_df <- data.frame(Y = rbeta(10000, 1, 2))
  %>% mutate(U = 1-2*Y,
             V = 1/Y,
             W = sqrt(Y))
  %>% mutate(fY = dbeta(Y, 1, 2),
             fU = (1+U)/2,
             fV = 2*(V-1)/V^3,
             fW = 4*W*(1-W^2))
) %>% head
           Y          U         V         W        fY        fU          fV
1 0.19680093  0.6063981  5.081277 0.4436225 1.6063981 0.8031991 0.062216775
2 0.33906316  0.3218737  2.949303 0.5822913 1.3218737 0.6609368 0.151967656
3 0.03944225  0.9211155 25.353525 0.1986007 1.9211155 0.9605578 0.002988662
4 0.70614699 -0.4122940  1.416136 0.8403255 0.5877060 0.2938530 0.293055828
5 0.58318359 -0.1663672  1.714726 0.7636646 0.8336328 0.4168164 0.283521106
6 0.24366291  0.5126742  4.104030 0.4936222 1.5126742 0.7563371 0.089809909
         fW
1 1.4252688
2 1.5394311
3 0.7630699
4 0.9877287
5 1.2732317
6 1.4933792
(ggplot(data = sim_df, aes(x = Y)) +
         geom_histogram(aes(y = after_stat(density)),
                        fill = 'goldenrod', color = 'black',
                        center = 0.02, binwidth = 0.04) +
         geom_line(aes(y=fY), linewidth = 1) +
         xlim(c(0,1)) +
         labs(x = 'y', y = expression(f[Y](y))) +
         theme_classic()) +

(ggplot(data = sim_df, aes(x = U)) +
   geom_histogram(aes(y=after_stat(density)),
                  fill = 'cornflowerblue', color = 'black',
                  center = 0.02, binwidth = 0.04) +
 geom_line(aes(y = fU),
           linewidth = 1) +
   xlim(-1,1) +
   labs(x = 'u', y = expression(f[U](u))) +
   theme_classic()) +

(ggplot(data = sim_df, aes(x = V)) +
   geom_histogram(aes(y=after_stat(density)),
                  fill = 'cornflowerblue', color = 'black',
                  center = 0.25, binwidth = 0.5) +
 geom_line(aes(y = fV),
           linewidth = 1) +
   xlim(1,40) +
   labs(x = 'v', y = expression(f[V](v))) +
   theme_classic()) +
  
  (ggplot(data = sim_df, aes(x = W)) +
   geom_histogram(aes(y=after_stat(density)),
                  fill = 'cornflowerblue', color = 'black',
                  center = 0.01, binwidth = 0.02) +
 geom_line(aes(y = fW),
           linewidth = 1) +
   xlim(0,1) +
   labs(x = 'w', y = expression(f[W](w))) +
   theme_classic())
Warning: Removed 504 rows containing non-finite outside the scale range
(`stat_bin()`).
Warning: Removed 504 rows containing missing values or values outside the scale range
(`geom_line()`).