Because when using pivot_wider, half is used as a key_variable. Afterwards, pivot_longer takes the first column in the pivot_wider result as the first column and the first row as the second column. You can make it work symmetrically by changing the code as follows.