Dear All, I have a dataset which contains date and 12 other countries data. I have extracted the data as xts object. I am not able to recall all the series in the Y axis. My data set looks like this index crepub finland france germany italy netherlands norway poland <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> 1 2005-01-03 1.21 0.615 1.90 3.01 0.346 0.509 1.05 1.13 2 2005-01-04 1.18 0.615 1.85 2.89 0.346 0.509 0.889 1.12 3 2005-01-05 1.15 0.615 1.81 2.78 0.346 0.509 0.785 1.09 4 2005-01-06 1.11 0.615 1.76 2.67 0.346 0.509 0.711 1.06 5 2005-01-07 1.08 0.615 1.72 2.57 0.346 0.509 0.661 1.02 6 2005-01-10 1.04 0.615 1.69 2.48 0.346 0.509 0.630 1.01 My code for the same is as follows ggplot(data=data_vol3, aes(x=index, y=data_vol3$usa)+ geom_line()) Any help in this regard will be highly appreciated With regards, Upananda Pani
Dear Upananda, I see a misplaced bracket in your code, and there is no need in aes() to call the dataframe explicitly. Does this work? ggplot(data = data_vol3, aes(x = index, y = usa)) + geom_line() Best wishes, Thomas ________________________________ Von: R-help <r-help-bounces at r-project.org> im Auftrag von Upananda Pani <upananda.pani at gmail.com> Gesendet: Dienstag, 2. Mai 2023 10:57 An: r-help <r-help at r-project.org> Betreff: [R] Reg: Help regarding ggplot2 Dear All, I have a dataset which contains date and 12 other countries data. I have extracted the data as xts object. I am not able to recall all the series in the Y axis. My data set looks like this index crepub finland france germany italy netherlands norway poland <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> 1 2005-01-03 1.21 0.615 1.90 3.01 0.346 0.509 1.05 1.13 2 2005-01-04 1.18 0.615 1.85 2.89 0.346 0.509 0.889 1.12 3 2005-01-05 1.15 0.615 1.81 2.78 0.346 0.509 0.785 1.09 4 2005-01-06 1.11 0.615 1.76 2.67 0.346 0.509 0.711 1.06 5 2005-01-07 1.08 0.615 1.72 2.57 0.346 0.509 0.661 1.02 6 2005-01-10 1.04 0.615 1.69 2.48 0.346 0.509 0.630 1.01 My code for the same is as follows ggplot(data=data_vol3, aes(x=index, y=data_vol3$usa)+ geom_line()) Any help in this regard will be highly appreciated With regards, Upananda Pani ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]]
It's not clear what you want but ... On 02/05/2023 10:57, Upananda Pani wrote:> Dear All, > > I have a dataset which contains date and 12 other countries data. I > have extracted the data as xts object. > > I am not able to recall all the series in the Y axis. My data set > looks like this > > index crepub finland france germany italy netherlands norway poland > <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> > 1 2005-01-03 1.21 0.615 1.90 3.01 0.346 0.509 1.05 1.13 > 2 2005-01-04 1.18 0.615 1.85 2.89 0.346 0.509 0.889 1.12 > 3 2005-01-05 1.15 0.615 1.81 2.78 0.346 0.509 0.785 1.09 > 4 2005-01-06 1.11 0.615 1.76 2.67 0.346 0.509 0.711 1.06 > 5 2005-01-07 1.08 0.615 1.72 2.57 0.346 0.509 0.661 1.02 > 6 2005-01-10 1.04 0.615 1.69 2.48 0.346 0.509 0.630 1.01 > > My code for the same is as follows > > ggplot(data=data_vol3, aes(x=index, y=data_vol3$usa)+ > geom_line())Well you don't need to say that the y data are from data_vol3, your data = declaration says that. I wonder if what you want is: library(tidyverse) tribble( ? ~rowN, ~index, ~crepub, ~finland, ~france, ~germany, ~italy, ~netherlands, ~norway, ~poland, ? 1, "2005-01-03", 1.21, 0.615, 1.90, 3.01, 0.346, 0.509, 1.05, 1.13, ? 2, "2005-01-04", 1.18, 0.615, 1.85, 2.89, 0.346, 0.509, 0.889, 1.12, ? 3, "2005-01-05", 1.15, 0.615, 1.81, 2.78, 0.346, 0.509, 0.785, 1.09, ? 4, "2005-01-06", 1.11, 0.615, 1.76, 2.67, 0.346, 0.509, 0.711, 1.06, ? 5, "2005-01-07", 1.08, 0.615, 1.72, 2.57, 0.346, 0.509, 0.661, 1.02, ? 6, "2005-01-10", 1.04, 0.615, 1.69, 2.48, 0.346, 0.509, 0.630, 1.01) -> data_vol3 ### please give us data using dput in future: saves us having to do something like that to reclaim it! ### pivot that longer to make it easy to get country data as separate lines data_vol3 %>%? select(-rowN) %>% ? pivot_longer(cols = -index, # as you want to pivot the other variables/columns ?????????????? names_to = "countries") -> tibDataVol3Long ggplot(data = tibDataVol3Long, ?????? aes(x = index, y = value, ???????????? ### now get the grouping and use it for a colour legend ???????????? group = countries, colour = countries)) + ? geom_line()> Any help in this regard will be highly appreciated > > With regards, > Upananda Pani > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Chris Evans (he/him) Visiting Professor, UDLA, Quito, Ecuador & Honorary Professor, University of Roehampton, London, UK. Work web site: https://www.psyctc.org/psyctc/ CORE site: http://www.coresystemtrust.org.uk/ Personal site: https://www.psyctc.org/pelerinage2016/ Emeetings (Thursdays): <https://www.psyctc.org/pelerinage2016/>https://www.psyctc.org/psyctc/booking-meetings-with-me/ (Beware: French time, generally an hour ahead of UK) <https://ombook.psyctc.org/book> [[alternative HTML version deleted]]
Dear Upananda, to complement the current response to your question, your data source looks like a "wide table" while you would certainly need them to be organised as a "long table", or to speak differently as a "tidy table". You should read this source in order to get a grasp on these issues: https://tidyr.tidyverse.org/articles/tidy-data.html Please note that the etiquette on this list states that example data should conform to some constraints that your message does not conform to (you shoud therefore also read the posting guide: http://www.R-project.org/posting-guide.html). Yours. Olivier. On Tue, 2 May 2023 14:27:24 +0530 Upananda Pani <upananda.pani at gmail.com> wrote:> Dear All, > > I have a dataset which contains date and 12 other countries data. I > have extracted the data as xts object. > > I am not able to recall all the series in the Y axis. My data set > looks like this > > index crepub finland france germany italy netherlands norway > poland <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> > <dbl> <dbl> 1 2005-01-03 1.21 0.615 1.90 3.01 0.346 > 0.509 1.05 1.13 2 2005-01-04 1.18 0.615 1.85 2.89 > 0.346 0.509 0.889 1.12 3 2005-01-05 1.15 0.615 1.81 > 2.78 0.346 0.509 0.785 1.09 4 2005-01-06 1.11 0.615 > 1.76 2.67 0.346 0.509 0.711 1.06 5 2005-01-07 1.08 > 0.615 1.72 2.57 0.346 0.509 0.661 1.02 6 2005-01-10 > 1.04 0.615 1.69 2.48 0.346 0.509 0.630 1.01 > > My code for the same is as follows > > ggplot(data=data_vol3, aes(x=index, y=data_vol3$usa)+ > geom_line()) > > Any help in this regard will be highly appreciated > > With regards, > Upananda Pani > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html and provide commented, > minimal, self-contained, reproducible code.-- Olivier Crouzet, PhD http://olivier.ghostinthemachine.space /Ma?tre de Conf?rences/ @LLING - Laboratoire de Linguistique de Nantes UMR6310 CNRS / Universit? de Nantes
Reorganize the data so that you have three columns Something more like this: Date Country Value 2005-01-03 Crepub 1.21 You ggplot statement has a mistake. The geom_line() should be outside the ggplot() call. You might then have a ggplot statement like ggplot(data=data_vol3, aes(x=Country, y=Value)) + geom_line() Just make sure that the data type(s) are what they need to be. Country is non-numeric, and I am not sure geom_line() will like that. I am not sure why one might draw a line connecting categorical items. Tim -----Original Message----- From: R-help <r-help-bounces at r-project.org> On Behalf Of Upananda Pani Sent: Tuesday, May 2, 2023 4:57 AM To: r-help <r-help at r-project.org> Subject: [R] Reg: Help regarding ggplot2 [External Email] Dear All, I have a dataset which contains date and 12 other countries data. I have extracted the data as xts object. I am not able to recall all the series in the Y axis. My data set looks like this index crepub finland france germany italy netherlands norway poland <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> 1 2005-01-03 1.21 0.615 1.90 3.01 0.346 0.509 1.05 1.13 2 2005-01-04 1.18 0.615 1.85 2.89 0.346 0.509 0.889 1.12 3 2005-01-05 1.15 0.615 1.81 2.78 0.346 0.509 0.785 1.09 4 2005-01-06 1.11 0.615 1.76 2.67 0.346 0.509 0.711 1.06 5 2005-01-07 1.08 0.615 1.72 2.57 0.346 0.509 0.661 1.02 6 2005-01-10 1.04 0.615 1.69 2.48 0.346 0.509 0.630 1.01 My code for the same is as follows ggplot(data=data_vol3, aes(x=index, y=data_vol3$usa)+ geom_line()) Any help in this regard will be highly appreciated With regards, Upananda Pani ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Hi Thomas, Thanks for your help. I need to plot all other countries as well. Thanks for your time With sincere regards, Upananda On Tue, May 2, 2023 at 3:01?PM Thomas.Rose <Thomas.Rose at daad-alumni.de> wrote:> Dear Upananda, > > I see a misplaced bracket in your code, and there is no need in aes() to > call the dataframe explicitly. Does this work? > > ggplot(data = data_vol3, aes(x = index, y = usa)) + > geom_line() > > Best wishes, > Thomas > > ------------------------------ > *Von:* R-help <r-help-bounces at r-project.org> im Auftrag von Upananda Pani > <upananda.pani at gmail.com> > *Gesendet:* Dienstag, 2. Mai 2023 10:57 > *An:* r-help <r-help at r-project.org> > *Betreff:* [R] Reg: Help regarding ggplot2 > > Dear All, > > I have a dataset which contains date and 12 other countries data. I > have extracted the data as xts object. > > I am not able to recall all the series in the Y axis. My data set > looks like this > > index crepub finland france germany italy netherlands norway poland > <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> > 1 2005-01-03 1.21 0.615 1.90 3.01 0.346 0.509 1.05 1.13 > 2 2005-01-04 1.18 0.615 1.85 2.89 0.346 0.509 0.889 1.12 > 3 2005-01-05 1.15 0.615 1.81 2.78 0.346 0.509 0.785 1.09 > 4 2005-01-06 1.11 0.615 1.76 2.67 0.346 0.509 0.711 1.06 > 5 2005-01-07 1.08 0.615 1.72 2.57 0.346 0.509 0.661 1.02 > 6 2005-01-10 1.04 0.615 1.69 2.48 0.346 0.509 0.630 1.01 > > My code for the same is as follows > > ggplot(data=data_vol3, aes(x=index, y=data_vol3$usa)+ > geom_line()) > > Any help in this regard will be highly appreciated > > With regards, > Upananda Pani > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]