1

This is the question:

Using a single pipe function, create a new variable called year_season that pastes together year and season (paste(year, season, sep="-")). Then, summarize the average, minimum, and maximum number of bikes and construct a plot with year_season on the x-axis and number of bikes on the y-axis. Show three lines (geom_line): one for the minimum, one for the maximum, and one for the average value. Somehow differentiate the max/min from the average value (you can use linetype, color, or line size to do this; completely up to you).

Note: In order for this to work, the first line of your plot needs to be this (without the quotes): 'ggplot(aes(year_season, count_avg, group=1)) +'

This is the code i've done but I'm not sure why this is wrong and why i'm not getting a plot:

bikes %>%
mutate(year_season = paste(year,season, sep="-")) %>%
summarize (avg_bikes=mean(count), min_bikes=min(count), 
max_bikes=max(count)) %>%
ggplot(aes(year_season,avg_bikes,group=1))+
geom_line(aes(avg_bikes, group=avg_bikes))+
geom_line(aes(min_bikes, group=min_bikes))+
geom_line(aes(max_bikes, group=max_bikes))
cpk
  • 11
  • 1
  • 3
    What error did you get? Moreover it seems that you did not ```group_by``` any variable so your are not really summarizing anything. I think that you want to do ```group_by(year_season)``` before summarizing. – c1au61o_HH Apr 19 '19 at 03:37
  • 3
    We don't have your data and can't see your output, so without a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) we don't know what's going on. This looks like your homework, though, so I'm guessing you probably have some class materials on using `ggplot2`, which generally takes long-shaped data and maps variables to aesthetics like color – camille Apr 19 '19 at 03:42

0 Answers0