[R] Plotting in R
David Carlson
dc@r|@on @end|ng |rom t@mu@edu
Thu Jul 11 19:51:17 CEST 2019
There's a typo in the first column name of your data - "year1" should
be "year". Sometimes R will do partial matching and find it, but not
always. Is this closer to what you're looking for?
plot(rate~year, sydf, type="b", xaxt="n", xlab="Month-Day")
axis(1, sydf$year, sydf$month.day)
This will probably leave out some labels because there is not enough
room. You can print the labels smaller:
axis(1, sydf$year, sydf$month.day, cex.axis=.75)
or rotate them 90 degrees:
axis(1, sydf$year, sydf$month.day, las=2)'
David L Carlson
Department of Anthropology
Texas A&M University
On Thu, Jul 11, 2019 at 10:59 AM <nstefi using gmail.com> wrote:
>
> Hi Jim,
>
> Thanks for your email.
> My question was: how to change the x axis labels without changing the chart.
> Or is that not possible?
> Using your example, I added another column:
> sydf<-read.table(text="year1 month-day rate
> 1993 05-01 0.608
> 1994 06-01 0.622
> 1996 07-01 0.623
> 1998 08-01 0.647
> 2000 09-01 0.646
> 2002 10-01 0.625
> 2004 11-01 0.628
> 2006 12-01 0.685
> 2008 01-01 0.679
> 2010 02-01 0.595
> 2012 03-01 0.567
> 2014 04-01 0.599
> 2016 05-01 0.642
> 2018 06-01 0.685",
> header=TRUE)
>
> How can I show the column "month-day" as labels on the x axis, but still
> have the plot showing the chart as rate based on year?
> I tried this:
> plot(sydf$year,sydf$rate,type="b",
> xlab="month-day",ylab="Rate")
>
> but this only changes the title of the x axis to "month-day". I want the
> values on the x axis to show 05-01 06-01, etc.
> Is that possible?
>
> Thanks,
> Steven
>
> -----Original Message-----
> From: R-help <r-help-bounces using r-project.org> On Behalf Of Jim Lemon
> Sent: Sunday, July 7, 2019 2:59 AM
> To: Steven Yen <styen using ntu.edu.tw>; r-help mailing list
> <r-help using r-project.org>
> Subject: Re: [R] Plotting in R
>
> 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 using 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 using ntu.edu.tw (S.T. Yen)
> >
> >
> >
> > ---
> > This email has been checked for viruses by Avast antivirus software.
> > https://urldefense.proofpoint.com/v2/url?u=https-3A__www.avast.com_antivirus&d=DwICAg&c=u6LDEWzohnDQ01ySGnxMzg&r=VAaHUElasUXjP9TzIcfIrXdkDpHnJBBZ9Q1u5LcXz9s&m=23NXOUvOhO2PZnfjNak-qt7MYdttWJs3O634wqpLE4A&s=Psw17kUMNN42CxAcroDYQ-fU3UzzQlXgwSdzbvb23Lc&e=
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp&d=DwICAg&c=u6LDEWzohnDQ01ySGnxMzg&r=VAaHUElasUXjP9TzIcfIrXdkDpHnJBBZ9Q1u5LcXz9s&m=23NXOUvOhO2PZnfjNak-qt7MYdttWJs3O634wqpLE4A&s=uruiNGrA6F82mRo7L3az2sIVhJv58RS7O3bC9JxKfKc&e=
> > PLEASE do read the posting guide
> > https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html&d=DwICAg&c=u6LDEWzohnDQ01ySGnxMzg&r=VAaHUElasUXjP9TzIcfIrXdkDpHnJBBZ9Q1u5LcXz9s&m=23NXOUvOhO2PZnfjNak-qt7MYdttWJs3O634wqpLE4A&s=Ic4wt1QLwaqf-_Ncfy9aN_dp_fqkFLoZl4zwa2Xj-r4&e=
> > and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp&d=DwICAg&c=u6LDEWzohnDQ01ySGnxMzg&r=VAaHUElasUXjP9TzIcfIrXdkDpHnJBBZ9Q1u5LcXz9s&m=23NXOUvOhO2PZnfjNak-qt7MYdttWJs3O634wqpLE4A&s=uruiNGrA6F82mRo7L3az2sIVhJv58RS7O3bC9JxKfKc&e=
> PLEASE do read the posting guide https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html&d=DwICAg&c=u6LDEWzohnDQ01ySGnxMzg&r=VAaHUElasUXjP9TzIcfIrXdkDpHnJBBZ9Q1u5LcXz9s&m=23NXOUvOhO2PZnfjNak-qt7MYdttWJs3O634wqpLE4A&s=Ic4wt1QLwaqf-_Ncfy9aN_dp_fqkFLoZl4zwa2Xj-r4&e=
> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp&d=DwICAg&c=u6LDEWzohnDQ01ySGnxMzg&r=VAaHUElasUXjP9TzIcfIrXdkDpHnJBBZ9Q1u5LcXz9s&m=23NXOUvOhO2PZnfjNak-qt7MYdttWJs3O634wqpLE4A&s=uruiNGrA6F82mRo7L3az2sIVhJv58RS7O3bC9JxKfKc&e=
> PLEASE do read the posting guide https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html&d=DwICAg&c=u6LDEWzohnDQ01ySGnxMzg&r=VAaHUElasUXjP9TzIcfIrXdkDpHnJBBZ9Q1u5LcXz9s&m=23NXOUvOhO2PZnfjNak-qt7MYdttWJs3O634wqpLE4A&s=Ic4wt1QLwaqf-_Ncfy9aN_dp_fqkFLoZl4zwa2Xj-r4&e=
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list