Displaying 2 results from an estimated 2 matches for "mean_tmin".
2018 Apr 29
1
Overlay line on a bar plot - multiple axis
...uld like
to have a horizontal bar plot of *count* by city and a line plot of weekly
average of the variable *z*.
I have tried the following:
ggplot() + geom_bar(data=dat, aes(x=city, y=count),
stat="identity",position="dodge") + coord_flip() +
geom_line(data=dat, aes(x=week, y=mean_tmin))
However, this flips the code for both the bar plot and the line plot. I
would the y-axis of the line plot to be on the left-vertical axis. I read
that it is difficult to have a secondary axis with ggplot. Any help will be
highly appreciated. Thank you!
dput(dat)
structure(list(city = structure(...
2018 Apr 30
1
Overlay line on a bar plot - multiple axis
Hi Miluji,
Using Jim's interpretation of your desired graph,
you could do it in ggplot2 using your dat DF by:
ggplot() +
geom_bar(data=dat,
aes(x=week,y=count,fill=city),stat="identity",position="dodge") +
coord_flip() +
geom_line(data=dat, aes(x=week, y=mean_tmin))
There would still need some work to be done to get the weekly mean
into a legend, but it is achievable if required.
Ron.