[R] Help with the plot function

André Luis Neves andrluis at ualberta.ca
Tue Jun 20 10:00:33 CEST 2017


Hi, Petr,

Indeed, your code is much better than the one I presented. I made small
editings.

par(mfrow = c(2, 1))
par(cex = 0.6)
par(mar = c(0, 0, 0, 0), oma = c(7, 7, 0.5, 5))
par(tcl = -0.25)
par(mgp = c(2, 0.6, 0))

plot(BUD~YEAR, type="o", ann=F, axes=F, pch=19, ylim=c(60,100),data=g1)
axis(2, las=2)
mtext("Bud Break (Julian Day)", side=2, padj=-3)
arrows(g1$YEAR,g1$BUD, g1$YEAR,g1$BUD + g1$BUD_SE, length=0.05, angle=90)
arrows(g1$YEAR,g1$BUD, g1$YEAR,g1$BUD-g1$BUD_SE, length=0.05, angle=90)

plot(T_MAR~YEAR, type="n", pch=19, ann=F, axes=F, xlim=c(1996,2004),
ylim=c(0,12), data=g1)
lines(T_MAR~YEAR, type="o", pch=0, lty=2)
lines(T_APR~YEAR, type="o", pch=8, lty=3)
lines(T_MAY~YEAR, type="o", pch=2, lty=4)

axis(1, at=seq(1996, 2004, 2))
axis(2, at=c(0,3,6,9,12), las=2)
mtext("Year", side=1, padj=4)
mtext("Temperature (°C)", side=2, padj=-3)

legend(1999,10, bty="n",
       lty = c(2,3,4),
       lwd = c(2,2,2),
       pch = c(0,8,2),
       legend = c("March","April","May"))

Thank you very much,

Andre


On Tue, Jun 20, 2017 at 1:12 AM, André Luis Neves <andrluis at ualberta.ca>
wrote:

> Dear all,
>
> I found the last example of this link (https://sites.ualberta.ca/~
> lkgray/uploads/7/3/6/2/7362679/6c_-_line_plots_with_error_bars.pdf) very
> similar to the one I need to make for my paper, and I think I got what I
> wanted by applying some of the suggestions of this mail list.
>
> Here it is the code I devised (maybe there will be further improvements
> from the list):
>
>
> YEAR <- c(1996 , 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 )
> T_MAR <- c(2.8, 6.5, 5.4,2.4, 4, 4.1, 3, 4.4, 4.5)
> T_APR <- c(5.7, 7.8, 7.7, 4.6, 4.7, 6.2,5.7, 5.9, 7)
> T_MAY <- c(7, 8.8, 10, 6, 5.5, 7.6, 8.5, 7.3, 10.2)
> BUD <- c(87, 98, 93, 85, 89, 91, 87, 92, 92)
> BUD_SE <- c(3.6, 2, 2.4, 4, 2.4, 2.4, 4, 2.4, 3)
> g1 <- data.frame(YEAR, T_MAR, T_APR, T_MAY, BUD, BUD_SE)
>
> par(mar=c(5,5,5,5))
> plot(YEAR,T_MAR,pch=0,type="b",col="green",yaxt="n",ylim=c(-
> 15,12),ylab="")
> lines(T_MAR~YEAR, type="o", pch=19, col="green")
> lines(T_APR~YEAR, type="o", pch=19, col="red")
> lines(T_MAY~YEAR, type="o", pch=19, col="blue")
> axis(side=2, at=c(0,6,12))
> mtext("Temperature (°C)", side = 2, line=2.5, at=6)
> legend(1999,14, bty="n",
>        lty = c(1,1,1),
>        lwd = c(2,2,2),
>        pch = c(19,19,19),
>        col = c("green","red","blue"), legend = c("March","April","May"))
>
> par(new=TRUE)
>
> plot(YEAR,BUD, pch=1,type="b",col="blue",yaxt="n",ylim=c(105,50), ylab="")
> arrows(g1$YEAR,g1$BUD, g1$YEAR,g1$BUD + g1$BUD_SE, length=0.05, angle=90)
> arrows(g1$YEAR,g1$BUD, g1$YEAR,g1$BUD-g1$BUD_SE, length=0.05, angle=90)
> axis(side=4, at=c(100,90,80), labels=c("80","90","100"),las=1)
> mtext("Bud Break (Julian Day)", side = 4, line=2.5, at=90, padj=0)
> abline(h=78)
>
>
> Thanks for the insight and help as to the functions I needed to take a
> look at.
>
> Andre
>
>
> On Tue, Jun 20, 2017 at 12:38 AM, PIKAL Petr <petr.pikal at precheza.cz>
> wrote:
>
>> Hi
>>
>> You are quite close. With slight modification of your code:
>>
>> par(mfrow = c(2, 1))
>> par(cex = 0.6)
>> par(mar = c(0, 0, 0, 0), oma = c(4, 4, 0.5, 0.5))
>> par(tcl = -0.25)
>> par(mgp = c(2, 0.6, 0))
>>
>> plot(BUD~YEAR, type="o", ann=F, axes=F, pch=19, ylim=c(60,100),data=g1)
>> axis(4, las=2)
>> mtext("Bud Break (Julian Day)", side=4, padj=4)
>> arrows(g1$YEAR,g1$BUD, g1$YEAR,g1$BUD + g1$BUD_SE, length=0.05, angle=90)
>> arrows(g1$YEAR,g1$BUD, g1$YEAR,g1$BUD-g1$BUD_SE, length=0.05, angle=90)
>>
>> plot(T_MAR~YEAR, type="l", pch=19, ann=F, axes=F, xlim=c(1996,2004),
>> ylim=c(0,12), data=g1)
>>
>> title(ylab="Temperature (°C)",xlab="Year")
>> axis(1, at=seq(1996, 2004, 2))
>> axis(2, at=c(0,3,6,9,12), las=2)
>>
>> I am quite close to what you probably expect. You need modify axes and
>> their annotation, which is left for your training.
>>
>> Cheers
>> Petr
>>
>> >
>>
>> > -----Original Message-----
>> > From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of André
>> Luis
>> > Neves
>> > Sent: Tuesday, June 20, 2017 6:29 AM
>> > To: Bert Gunter <bgunter.4567 at gmail.com>
>> > Cc: R mailing list <r-help at r-project.org>
>> > Subject: Re: [R] Help with the plot function
>> >
>> > Hi, Bert:
>> > Yes, I studied the functions you suggested, but I didn't get to adapt
>> it to
>> > my example whose reproducible code I sent in my first email.
>> >
>> > Here it is the code of the functions I studies:
>> >
>> > ## par
>> > par(mfrow = c(2, 3))
>> > par(cex = 0.6)
>> > par(mar = c(3, 3, 0, 0), oma = c(1, 1, 1, 1))
>> > for (i in 1:6) {
>> >  plot(1, 1, type = "n")
>> > mtext(letters[i], side = 3, line = -1, adj = 0.1, cex = 0.6)}
>> >
>> >
>> > par(mfrow = c(2, 3))
>> > par(cex = 0.6)
>> > par(mar = c(0, 0, 0, 0), oma = c(4, 4, 0.5, 0.5))
>> > par(tcl = -0.25)
>> > par(mgp = c(2, 0.6, 0))
>> >
>> > for (i in 1:6) {
>> >       plot(1, axes = FALSE, type = "n")
>> >       mtext(letters[i], side = 3, line=-1,adj=0.1,cex=0.6, col =
>> "grey40")
>> >   if (i %in% c(4, 5, 6))
>> >     axis(1, col = "grey40", col.axis = "grey20", at = seq(0.6,
>> >                                                           1.2, 0.2))
>> >   if (i %in% c(1, 4))
>> >     axis(2, col = "grey40", col.axis = "grey20", at = seq(0.6,
>> >                                                           1.2, 0.2))
>> >   box(col = "grey60")}
>> >
>> > ## Layout
>> >
>> > m <- rbind(c(1, 1), c(2, 3))
>> > m
>> > layout(m)
>> > layout.show(3)
>> > layout(m)
>> > par(mar = c(3, 3, 0, 0))
>> > for (i in 1:3) plot(1, 1, type = "n")
>> >
>> > Thank you,
>> >
>> > Andre
>> >
>> >
>> > On Mon, Jun 19, 2017 at 9:53 PM, Bert Gunter <bgunter.4567 at gmail.com>
>> > wrote:
>> >
>> > > 1. Did you study the functions (esp. ?layout) to which I referred you?
>> > >
>> > > 2. Show us your code! -- "to no avail" is meaningless!
>> > >
>> > > -- Bert
>> > >
>> > >
>> > > 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 Mon, Jun 19, 2017 at 7:01 PM, André Luis Neves <
>> andrluis at ualberta.ca>
>> > > wrote:
>> > > > I'm trying to recreate a graph similar to the last one found on this
>> > > link:
>> > > > https://sites.ualberta.ca/~lkgray/uploads/7/3/6/2/
>> > > 7362679/6c_-_line_plots_with_error_bars.pdf
>> > > >
>> > > > The difference is that I want budbreak on the top, and the
>> temperatures
>> > > at
>> > > > the bottom.
>> > > >
>> > > > I tried to set par before each graph and include lines, with no
>> avail.
>> > > >
>> > > > Thanks, Bert.
>> > > >
>> > > > Andre
>> > > >
>> > > > On Mon, Jun 19, 2017 at 7:41 PM, Bert Gunter <
>> bgunter.4567 at gmail.com>
>> > > wrote:
>> > > >>
>> > > >> See
>> > > >>
>> > > >> ?layout
>> > > >> ?split.screen
>> > > >> ?par  (the mfrow and mfcol values)
>> > > >>
>> > > >> depending exactly on what you want to do and how you want to do it.
>> > > >> Essentially, these all allow you to make separate plots at
>> different
>> > > >> regions of the device.
>> > > >>
>> > > >>
>> > > >> Cheers,
>> > > >> Bert
>> > > >>
>> > > >>
>> > > >>
>> > > >>
>> > > >> 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 Mon, Jun 19, 2017 at 6:30 PM, André Luis Neves
>> > <andrluis at ualberta.ca
>> > > >
>> > > >> wrote:
>> > > >> > Dear friends,
>> > > >> >
>> > > >> > I have the following dataframe:
>> > > >> >
>> > > >> > YEAR <- c(1996 , 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 )
>> > > >> > T_MAR <- c(2.8, 6.5, 5.4,2.4, 4, 4.1, 3, 4.4, 4.5)
>> > > >> > T_APR <- c(5.7, 7.8, 7.7, 4.6, 4.7, 6.2,5.7, 5.9, 7)
>> > > >> > T_MAY <- c(7, 8.8, 10, 6, 5.5, 7.6, 8.5, 7.3, 10.2)
>> > > >> > BUD <- c(87, 98, 93, 85, 89, 91, 87, 92, 92)
>> > > >> > BUD_SE <- c(3.6, 2, 2.4, 4, 2.4, 2.4, 4, 2.4, 3)
>> > > >> > g1 <- data.frame(YEAR, T_MAR, T_APR, T_MAY, BUD, BUD_SE)
>> > > >> >
>> > > >> > ###PLOT
>> > > >> > dev.new(width=6.5, height=5)
>> > > >> > par (cex=1, family="sans", mar=c(5,5,5,5.5))
>> > > >> > plot(T_MAR~YEAR, type="l", pch=19, ann=F, axes=F,
>> xlim=c(1996,2004),
>> > > >> > ylim=c(0,12), data=g1)
>> > > >> >
>> > > >> > title(ylab="Temperature (°C)",xlab="Year")
>> > > >> > axis(1, at=seq(1996, 2004, 2))
>> > > >> > axis(2, at=c(0,3,6,9,12), las=2)
>> > > >> > par(new=T)
>> > > >> > plot(BUD~YEAR, type="o", ann=F, axes=F, pch=19,
>> > > ylim=c(60,100),data=g1)
>> > > >> > axis(4, las=2)
>> > > >> > mtext("Bud Break (Julian Day)", side=4, padj=4)
>> > > >> > arrows(g1$YEAR,g1$BUD, g1$YEAR,g1$BUD + g1$BUD_SE, length=0.05,
>> > > >> > angle=90)
>> > > >> > arrows(g1$YEAR,g1$BUD, g1$YEAR,g1$BUD-g1$BUD_SE, length=0.05,
>> > > angle=90)
>> > > >> >
>> > > >> >
>> > > >> >
>> > > >> > However, I'd like to draw a multi-panel graph with budbreak on
>> the top
>> > > >> > (as
>> > > >> > it is), and with the temperatures for March, April, and May on
>> the
>> > > >> > bottom,
>> > > >> > with their respective legends.
>> > > >> >
>> > > >> > I was wondering if you could help me out with this.
>> > > >> >
>> > > >> > Thanks a million for your help.
>> > > >> >
>> > > >> > --
>> > > >> > Andre
>> > > >> >
>> > > >> >         [[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.
>> > > >
>> > > >
>> > > >
>> > > >
>> > > > --
>> > > > Andre
>> > >
>> >
>> >
>> >
>> > --
>> > Andre
>> >
>> >       [[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/posti
>> ng-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>>
>> ________________________________
>> Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou
>> určeny pouze jeho adresátům.
>> Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě
>> neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie
>> vymažte ze svého systému.
>> Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento
>> email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
>> Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi
>> či zpožděním přenosu e-mailu.
>>
>> V případě, že je tento e-mail součástí obchodního jednání:
>> - vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření
>> smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu.
>> - a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně
>> přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze
>> strany příjemce s dodatkem či odchylkou.
>> - trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve
>> výslovným dosažením shody na všech jejích náležitostech.
>> - odesílatel tohoto emailu informuje, že není oprávněn uzavírat za
>> společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn
>> nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto
>> emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich
>> existence je adresátovi či osobě jím zastoupené známá.
>>
>> This e-mail and any documents attached to it may be confidential and are
>> intended only for its intended recipients.
>> If you received this e-mail by mistake, please immediately inform its
>> sender. Delete the contents of this e-mail with all attachments and its
>> copies from your system.
>> If you are not the intended recipient of this e-mail, you are not
>> authorized to use, disseminate, copy or disclose this e-mail in any manner.
>> The sender of this e-mail shall not be liable for any possible damage
>> caused by modifications of the e-mail or by delay with transfer of the
>> email.
>>
>> In case that this e-mail forms part of business dealings:
>> - the sender reserves the right to end negotiations about entering into a
>> contract in any time, for any reason, and without stating any reasoning.
>> - if the e-mail contains an offer, the recipient is entitled to
>> immediately accept such offer; The sender of this e-mail (offer) excludes
>> any acceptance of the offer on the part of the recipient containing any
>> amendment or variation.
>> - the sender insists on that the respective contract is concluded only
>> upon an express mutual agreement on all its aspects.
>> - the sender of this e-mail informs that he/she is not authorized to
>> enter into any contracts on behalf of the company except for cases in which
>> he/she is expressly authorized to do so in writing, and such authorization
>> or power of attorney is submitted to the recipient or the person
>> represented by the recipient, or the existence of such authorization is
>> known to the recipient of the person represented by the recipient.
>>
>
>
>
> --
> Andre
>



-- 
Andre

	[[alternative HTML version deleted]]



More information about the R-help mailing list