second y-axis in r with other scale [duplicate]

second y-axis in r with other scale [duplicate]



This question already has an answer here:



I want to plot something in R and need a second y-axis with a different scale. Is there a special command? I have found some hints, but they were not helping me so much. I tried to plot it like this first:


A <- c(1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016)
B <- c(11, 952, 116, 37, 130, 435, 159, 184, 465, 561, 456, 837, 649, 459, 531, 196, 265, 121, 184, 270, 1170, 273, 212, 357, 298, 518, 200, 108, 68, 52, 75, 158, 74, 78, 242, 251, 371, 493, 242, 396, 53, 95)
C <- c(0, 313, 11, 0, 26, 59, 13, 13, 40, 223, 159, 109, 65, 68, 38, 14, 15, 21, 9, 25, 11, 24, 31, 50, 49, 185, 47, 72, 29, 13, 22, 17, 10, 34, 22, 7, 9, 10, 8, 18, 11, 17)
plot(A,B)
lines(A,C, type="b")



But it just makes them in one plot with one y-axis.



I shortend the code a bit, the rest of it is not so important. I would like to have the ylim of b at 1500, and the ylim of C at 350. The axis plot creates just another axis with the same scale.



I want it to look like this:



![link](https://upload.worldofplayers.de/files11/jUDFhhGOsaUVU1WlnUnbenannt.png)



Can anyone of you help me?



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





Welcome to SO! Please provide a reproducible question, including sample data and why the current output is not correct. Some good references for reproducibility: stackoverflow.com/questions/5963269, stackoverflow.com/help/mcve, and stackoverflow.com/tags/r/info. (For instance, your mention of 1500 and 350 have absolutely no meaning since we know nothing of your data.)
– r2evans
Sep 3 at 16:26





But perhaps all you need is to try the axis command?
– r2evans
Sep 3 at 16:27


axis





Welcome to Stack Overflow. Since we do not have your A, B or C, we cannot run your code and see what you are trying to get. Please use dput to include your data in your question. If the data is too long, you might try dput(head(A, 15))_
– G5W
Sep 3 at 16:28


dput


dput(head(A, 15))_





(1) Because comments are easily ignored or hidden, please put everything that is relevant to your question within the question itself. For that, please edit your question and put your sample data there. (2) If your second axis is on the wrong side, did you read how the side= arguments works? Perhaps it's as simple as axis(side=3,...).
– r2evans
Sep 3 at 17:12


side=


axis(side=3,...)





Tsamsiyu, I edited the question to make the sample data something we can use more easily (since we cannot copy A <- 1975 1976 1977 directly without c(...) and commas). Please think about making it easy to copy/paste, you will be more likely to get somebody to give it a try.)
– r2evans
Sep 3 at 18:22


A <- 1975 1976 1977


c(...)




Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế