I was hoping to pick people's brain on better way visualize data that appears like this:

  • Two categorical variables
  • One continuous variable

I'm trying to visualize this data in way that is more appropriate than heat map. Does anyone have any suggestions?

Here's the code plus data (Note: There are more rows than the example data I have provided.):

test_data <- structure(list(Toys = c("Slinky", "Slinky", "Slinky", "Slinky", 
                                     "Slinky", "Slinky", "Tin Solider", "Tin Solider", "Tin Solider", 
                                     "Tin Solider", "Tin Solider", "Tin Solider", "Hungry Hungry Hippo", 
                                     "Hungry Hungry Hippo", "Hungry Hungry Hippo", "Hungry Hungry Hippo", 
                                     "Hungry Hungry Hippo", "Hungry Hungry Hippo"), 
                            Manufacturer = c("Manufacturer A", "Manufacturer B", "Manufacturer C", "Manufacturer A", "Manufacturer A", 
                                             "Manufacturer A", "Manufacturer B", "Manufacturer B", "Manufacturer B", 
                                             "Manufacturer B", "Manufacturer B", "Manufacturer B", "Manufacturer C", 
                                             "Manufacturer C", "Manufacturer C", "Manufacturer C", "Manufacturer C", 
                                             "Manufacturer C"), 
                            Price = c(5.99, 6.99, 7.99, 9, 6, 5.54, 7, 
                                      9.99, 6.99, 6.75, 8, 7.99, 9.99, 7.99, 5.99, 8.99, 10.99, 9.75)), 
                           class = "data.frame", row.names = c(NA, -18L))

melted_test_data <- reshape::melt(test_data %>% select(Toys,Manufacturer, Price))

plot_test_data <- melted_test_data %>% 
  ggplot(aes(x = Manufacturer, y = Toys, fill = value)) +
  geom_tile() +
  scale_fill_distiller(palette = 'Accent', label =  label_comma()) + 
  theme(panel.background = element_rect(fill = 'white'), axis.text.x = element_text(angle = 45, hjust = 1), plot.title = element_text(hjust = 0.5)) +
  labs(title ="Price by Manufacturer and Toys", x = "Manufacturers", y = "Manufacturer") +
  guides(fill = guide_colourbar(title = "price($)"))

1 Answer 1


If you want to make some kind of comparison of cost across the categories and the manufacturer, then you can compare the prices on mean/median.


test_data %>%
  group_by(Toys, Manufacturer) %>%
  summarise(Price=mean(Price)) %>%
  geom_bar(aes(x=Manufacturer, y=Price, fill=Toys), stat = 'identity',position = 'dodge')+
  scale_fill_brewer(palette = 'Set1')+
  theme(legend.position = 'top')

enter image description here

Side note:

Significance of the graph?

Hungry Hippo and Tin soldier are made by only 1 Manufacturer while Slinky is produced by all three. Even though it is produced by all the three manufacturers, the average price varies and it is the highest for Manufacturer C.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.