user14328853
user14328853

Reputation: 434

Remove facets from ggplot and instead display on a single chart?

Here is a plot that is very similar to one that I made for a stakeholder:

diamonds %>% 
  group_by(cut, color) %>% 
  summarise(av_price = mean(price)) %>% 
  ggplot(aes(color)) +
  geom_bar(aes(weight = av_price)) +
  facet_wrap(cut ~ .)

Looks like: enter image description here

I've been asked to remove the facets and instead display each cut on the same chart but with some space between each (and perhaps each with their own color for readability?)

I do not know how to get this done. Tried:

diamonds %>% 
  group_by(cut, color) %>% 
  summarise(av_price = mean(price)) %>% 
  ggplot(aes(color, cut)) +
  geom_bar(aes(weight = av_price))

Error: stat_count() can only have an x or y aesthetic.

How can I display each cut on a single chart as opposed to facets?

Upvotes: 0

Views: 116

Answers (1)

igutierrez
igutierrez

Reputation: 123

How about this solution:

diamonds %>% 
  group_by(cut, color) %>% 
  summarise(av_price = mean(price)) %>% 
  ggplot(aes(color, av_price, fill=cut)) +
  geom_col(position="dodge") +
  facet_wrap(~cut, nrow=1) +
  theme(strip.text.x = element_blank())

image

Upvotes: 1

Related Questions