0

I am trying to create a two-way bar graph in r. Or a bar graph with two y-axis for different variables.

I have the following code:

x<-c("1820s", "1830s", "1840s", "1850s", "1860s", "1870s", "1880s", "1890s", "1900s")
y<- cbind(c(1.16, 1.36, 1.10, 1.16, 1.18, 1.19, 1.26, 1.32, 1.95)
y2<-c(58.71, 54.42, 39.36, 41.7, 51.14, 50.35, 59.53, 58.88, 75.31)

bp<-barplot(t(y), beside=TRUE)
xlim<-c(floor(min(bp)), ceiling(max(BP)))
par(new=TRUE)

However, from here, I'm not sure how to insert the second variable.

I would like for the format of my bargraph to look similar to this.

enter image description here

Dyllan
  • 117
  • 10
  • 2
    that plot is confusing and pretty misleading. there are also a few bugs in your code--you should make sure it runs correctly before positing here. anyway, you can do it with `?axis`, something like `axis(4, at = c(0, 500000, 1000000), labels = c('0', '25,000', '50,000'))` – rawr Jul 04 '14 at 18:43
  • possible duplicate of [How can I plot with 2 different y-axes in R?](http://stackoverflow.com/questions/6142944/how-can-i-plot-with-2-different-y-axes-in-r) – Henrik Jul 04 '14 at 19:28

0 Answers0