Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

In R, how do I create a bar graph using a categorical x and the average of a numeric y with ggplot2?

$
0
0

I am using R version 3.5.1.

I started with this problem, and used the code suggested by the top comment on my own dataset, where time_len is a categorical variable telling how long it takes to play game i, with values of short, medium, and long; num_fans is a numeric variable telling how many fans game i has:

ggplot(cdata) +
  aes(x = time_len, y = num_fans) +
  geom_bar(stat = "identity")

Here is the plot:

bar chart of the data

I created the bar chart using the code above, but the problem is that the num_fans variable looks like it is a total. I want it to show the average for each category.

Is there a way to show the average of num_fans?


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>