I have a data frame containing two variables: year and rate (shown below). Which function can I use to plot rate (y-axis) against year (x-axis)? There will be more columns of rate later on. Thank you. year rate 1 1993 0.608 2 1994 0.622 3 1996 0.623 4 1998 0.647 5 2000 0.646 6 2002 0.625 7 2004 0.628 8 2006 0.685 9 2008 0.679 10 2010 0.595 11 2012 0.567 12 2014 0.599 13 2016 0.642 14 2018 0.685 -- styen at ntu.edu.tw (S.T. Yen) --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus [[alternative HTML version deleted]]
Oh come on! Please do your homework and spend time with some basic R tutorials, one of which ships with R, although there are tons more good ones on the web. And FYI, there are *several* different plotting systems that one can access using various R packages. Probably the most basic -- but still quite powerful -- uses the function ?plot !! Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sat, Jul 6, 2019 at 6:33 AM Steven Yen <styen at ntu.edu.tw> wrote:> I have a data frame containing two variables: year and rate (shown below). > Which function can I use to plot rate (y-axis) against year (x-axis)? > There will be more columns of rate later on. > Thank you. > > year rate 1 1993 0.608 2 1994 0.622 3 1996 0.623 4 1998 0.647 5 2000 > 0.646 6 2002 0.625 7 2004 0.628 8 2006 0.685 9 2008 0.679 10 2010 0.595 > 11 2012 0.567 12 2014 0.599 13 2016 0.642 14 2018 0.685 > > > -- > styen at ntu.edu.tw (S.T. Yen) > > > > --- > This email has been checked for viruses by Avast antivirus software. > https://www.avast.com/antivirus > > [[alternative HTML version deleted]] > > ______________________________________________ > 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]]
Hello, Please don't post inHTML, the data is unreadable. As for the question, it is very basic. try any of plot(rate ~ year, data = df) # df is your dataframe plot(df$year, df$rate) Then read ?plot and ?par to see how to customize the graph, by changing the plot type, how to add colors, etc. Hope this helps, Rui Barradas Citando Steven Yen <styen at ntu.edu.tw>:> I have a data frame containing two variables: year and rate (shown below). > Which function can I use to plot rate (y-axis) against year (x-axis)? > There will be more columns of rate later on. > Thank you. > > year rate 1 1993 0.608 2 1994 0.622 3 1996 0.623 4 1998 0.647 5 2000 > 0.646 6 2002 0.625 7 2004 0.628 8 2006 0.685 9 2008 0.679 10 2010 0.595 > 11 2012 0.567 12 2014 0.599 13 2016 0.642 14 2018 0.685 > > > -- > styen at ntu.edu.tw (S.T. Yen) > > > > --- > This email has been checked for viruses by Avast antivirus software. > https://www.avast.com/antivirus > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.
Please do not post in html. You could use ggplot to do this. But you need to do a bit of work yourself. On Sat, 6 Jul 2019 at 10:51, <ruipbarradas at sapo.pt> wrote:> > Hello, > > Please don't post inHTML, the data is unreadable. > > As for the question, it is very basic. try any of > > > plot(rate ~ year, data = df) # df is your dataframe > plot(df$year, df$rate) > > > Then read ?plot and ?par to see how to customize the graph, by > changing the plot type, how to add colors, etc. > > Hope this helps, > > Rui Barradas > > > > Citando Steven Yen <styen at ntu.edu.tw>: > > > I have a data frame containing two variables: year and rate (shown below). > > Which function can I use to plot rate (y-axis) against year (x-axis)? > > There will be more columns of rate later on. > > Thank you. > > > > year rate 1 1993 0.608 2 1994 0.622 3 1996 0.623 4 1998 0.647 5 2000 > > 0.646 6 2002 0.625 7 2004 0.628 8 2006 0.685 9 2008 0.679 10 2010 0.595 > > 11 2012 0.567 12 2014 0.599 13 2016 0.642 14 2018 0.685 > > > > > > -- > > styen at ntu.edu.tw (S.T. Yen) > > > > > > > > --- > > This email has been checked for viruses by Avast antivirus software. > > https://www.avast.com/antivirus > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > 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. > > ______________________________________________ > 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.-- John Kane Kingston ON Canada
Hi Steven, A basic plot can be displayed like this: sydf<-read.table(text="year rate 1993 0.608 1994 0.622 1996 0.623 1998 0.647 2000 0.646 2002 0.625 2004 0.628 2006 0.685 2008 0.679 2010 0.595 2012 0.567 2014 0.599 2016 0.642 2018 0.685", header=TRUE) plot(sydf$year,sydf$rate,type="b", xlab="Year",ylab="Rate") When you add more years and rates to the data frame, the axes will change to include the years and rates outside the ones in your example. As some have noted, this is a very basic question. Jim On Sat, Jul 6, 2019 at 11:33 PM Steven Yen <styen at ntu.edu.tw> wrote:> > I have a data frame containing two variables: year and rate (shown below). > Which function can I use to plot rate (y-axis) against year (x-axis)? > There will be more columns of rate later on. > Thank you. > > year rate 1 1993 0.608 2 1994 0.622 3 1996 0.623 4 1998 0.647 5 2000 > 0.646 6 2002 0.625 7 2004 0.628 8 2006 0.685 9 2008 0.679 10 2010 0.595 > 11 2012 0.567 12 2014 0.599 13 2016 0.642 14 2018 0.685 > > > -- > styen at ntu.edu.tw (S.T. Yen) > > > > --- > This email has been checked for viruses by Avast antivirus software. > https://www.avast.com/antivirus > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.