Read in Data

rankings_data <- read_excel(here("data/food_sorting_data.xlsx"))
rankings_data
## # A tibble: 32 × 85
##    `Participant ID` banana_cost apple_cost orange_cost papaya_cost avocado_cost
##               <dbl>       <dbl>      <dbl>       <dbl>       <dbl>        <dbl>
##  1                2          27         23          21          28           26
##  2                5          24         26          25          21           22
##  3                3          19         17          18          25           26
##  4                1          27         21          20          28           19
##  5                4          23         18          19          28           26
##  6               11          23         25          26          21           22
##  7                6          11         10           9          17           26
##  8               10          22         23          21          28           24
##  9                7          28         21          22          27           25
## 10                8          26         21          20          24           28
## # ℹ 22 more rows
## # ℹ 79 more variables: eggplant_cost <dbl>, laupele_cost <dbl>,
## #   rice_cost <dbl>, bread_cost <dbl>, cereal_cost <dbl>,
## #   breadfruit_cost <dbl>, eggs_cost <dbl>, spam_cost <dbl>,
## #   frychix_cost <dbl>, shoyuchix_cost <dbl>, mackerel_cost <dbl>,
## #   bakedchix_cost <dbl>, chips_cost <dbl>, cookies_cost <dbl>,
## #   pancake_cost <dbl>, icecream_cost <dbl>, pizza_cost <dbl>, …
rankings_data_tidy <- rankings_data %>%
  pivot_longer(
    cols = starts_with(c("banana_", "apple_", "orange_", "papaya_", "avocado_", "eggplant_", 
                         "laupele_", "rice_", "bread_", "cereal_", "breadfruit_", "eggs_", 
                         "spam", "frychix_", "pancake_", "icecream_", "pizza_", "hamburger_", 
                         "nuggets_", "fries_", "juices_", "soda_", "water_", "shoyuchix_", 
                         "mackerel_", "bakedchix_", "chips_", "cookies_")),
    names_to = "food_characteristic",
    values_to = "value"
  ) %>%
  separate(food_characteristic, into = c("food", "characteristic"), sep = "_", remove = FALSE) %>%
  select(-food_characteristic)
rankings_data_tidy
## # A tibble: 2,688 × 4
##    `Participant ID` food   characteristic value
##               <dbl> <chr>  <chr>          <dbl>
##  1                2 banana cost              27
##  2                2 banana social            23
##  3                2 banana healthy            3
##  4                2 apple  cost              23
##  5                2 apple  social            22
##  6                2 apple  healthy            2
##  7                2 orange cost              21
##  8                2 orange social            20
##  9                2 orange healthy            8
## 10                2 papaya cost              28
## # ℹ 2,678 more rows
rankings_data_wide <- rankings_data_tidy %>%
  pivot_wider(
    names_from = characteristic,
    values_from = value
  )
plot <- ggplot(data = rankings_data_wide, 
       aes(x = cost,
           y = social, 
           size = healthy,
           color = food)) +
  geom_point(alpha = 0.5) +
  theme_minimal() +
  scale_color_viridis(discrete=TRUE)

ggplotly(plot)
rankings_data_tidy <- rankings_data_tidy %>% 
  group_by(food) %>% 
  mutate(median = median(value, na.rm = TRUE))
ggplot(data = rankings_data_tidy, aes(y = reorder(food, median), x = value, fill = characteristic)) +
  geom_boxplot() +
  theme_minimal() +
  facet_wrap(~characteristic)
## Warning: Removed 337 rows containing non-finite values (`stat_boxplot()`).