0

I am currently working on a project regarding buying behaviour.

First I need to filter the data set because I only want to look at data which has a specific variable at one. Then I want to plot the data from this specific variable, distinguishing between A and B on x axis and having The Units on the y axis, unfortunately units are not the same for each data point so I cannot use a bar plot. My code currently is:

df1 %>% 
  filter(SES == "1") %>% 
  ggplot(aes(x = brand, y = unit)) +
  geom_col() +
  labs(y = "Units sold",
       x = "Brand", title="Buying Behaviour SES 1") +
  theme_bw(base_size = 15) 

This code works, but it does not show the results in percentage but rather in absolut value. I need to compare different SES and the absolute values differ strongly so I want to go with percentages instead. How would you guys change to percentage?

aes(y = (..count..)/sum(..count..))

using this does work for a bar plot if i leave out units, but I need to leave units in.

Chris
  • 1
  • 1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jun 27 '22 at 18:13
  • What kind of 'units' do you mean, and where do you want to leave them in? – Caspar V. Jun 27 '22 at 18:14
  • @CasparV. Sorry for the bad explanation. This data set shows purchases in a store. The whole data set only has purchases of one product category, cheese. Each purchase is listed as an entry but not each purchase has the same amount of units purchased. I dont want to compare the amount of purchases but rather the amount of units purchased. Hope this explains the issue better. – Chris Jun 27 '22 at 18:20
  • Could you please share some reproducible data using `dput`? – Quinten Jun 27 '22 at 18:39

0 Answers0