Get startedGet started for free

Plot shares for chocolate bars

A picture will help bring those share predictions to life and make it easy for people to understand. Let's make a bar plot of the shares.

This exercise is part of the course

Choice Modeling for Marketing in R

View Course

Exercise instructions

  • I've written the first line of code that computes the shares and saves them to shares.
  • You should fill in the missing inputs to barplot(). The first input should be the shares, which are stored in shares$share.
  • The second input should be the names of the different types of chocolate, which we can get from the chocolate data levels(chocolate$Type)

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# compute and save the share prediction 
shares <- predict_mnl(choc_m2, ghir_choc)

# make a barplot of the shares
barplot(____, 
        horiz = TRUE, col="tomato2",
        xlab = "Predicted Market Share", 
        main = "Shares for Ghiradelli chocolate bars at $3 each", 
        names.arg = ____)
Edit and Run Code