[R] plot with 2 y axes
Greg.Snow at imail.org
Wed Jan 26 16:54:59 CET 2011
Why do you need the line to overlay the bars? Which bars are touched by the line is just a quirk of scaling and could easily change with the scales. All the overlay does is to make it harder to read, why not jut have 2 panels aligned on the x-axis but with the line plot above the bar plot?
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
greg.snow at imail.org
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Mario Beolco
> Sent: Tuesday, January 25, 2011 5:31 PM
> To: r-help at r-project.org
> Subject: [R] plot with 2 y axes
> Dear R users,
> apologies for the total beginner's question. I would like to create a
> barchart for some temperature values with the y axis on the right hand
> side of the plot. On this plot would like to overlay some time series
> data (in the form of a line) for some other variable called Index.
> The y axis for this latter variable should be on the left hand side of
> the plot.
> An example of what I would like to obtain:
> I have tried to do this using ggplot2 and this where I have got (for
> data see at the bottom of the e-mail):
> p1 + geom_line(data=tmp3, aes(x=year, y=Index),
> This code does not do what I want because the Temperature y axis
> should be on the left hand side and the the y axis for the other
> variable called Index is not even there (should in theory be on the
> left hand side). I also get the following warning message when I run
> that code "I get Warning message:Stacking not well defined when ymin
> != 0". (Should I worry about this?).
> I do not know whether ggplot2 can is the best package for creating the
> type of plot that I want. I would, however, be very grateful for any
> suggestions on to improve the above code or on how I could use other
> packages to create the plot I want.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help