0

I have the dataframe in this format. I want to plot bar graph overlapping each other for each day_of_week.

day_of_week clicks impressions
        <int>  <int>       <int>
1           0  65181     3778745
2           1  54658     2912405
3           2  50020     3016874

I am using this code. But it throws me an error :

ggplot(weekday_count, aes(x=day_of_week)) +                    # basic graphical object
  geom_bar(aes(y=clicks), colour="red") +  # first layer
  geom_bar(aes(y=impressions), colour="green")  # second layer

Error: stat_count() must not be used with a y aesthetic.

4
  • Do you give a look at ggplot2 documentation ? Especially geom_bar. I Think you are looking for something like : how-to-overlay-two-geom-bar Commented May 3, 2018 at 12:41
  • Possible duplicate of How to overlay two geom_bar? Commented May 3, 2018 at 12:45
  • @Thomas I have edited the question Commented May 3, 2018 at 12:46
  • Use geom_col. Possibly reshape your data. Commented May 3, 2018 at 12:48

1 Answer 1

3

given your code, i think what you are looking for is

dd = read.table(text = 'day_of_week clicks impressions

          0  65181     3778745
          1  54658     2912405
          2  50020     3016874', header = T)

dd = melt(dd, id.vars = 'day_of_week')

ggplot(data = dd, aes(x = day_of_week, y = value, fill = variable)) +
  geom_col(alpha = 0.5, position = 'identity')

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.