barplot_add=TRUE

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

barplot_add=TRUE

"Sibylle Stöckli"
Dear R users

aim
Barplot of insect trap catches (y variable trapcatch) at one specific station (variable FiBL_Hecke) from week 1-52 ( x variable week).
It works well using the function tapply (sum trapcatch per week, males and females not separated), however, I intend to separate the y variable trapcatch in males and females (variable m_w: m and w)

problem
I used the function "add" to merge two bar plots (males and females). Unfortunately the second barplot masks the first barplot.

question
Is there a function to "mathematically" add the values from both barplots with the aim the barplot presenting the total trap (males and females) catches per week?



Hecke<-trap[trap$station=="FiBL_Hecke",] # station = Hecke
m<-Hecke[Hecke$m_w=="m",] # male trap catches
w<-Hecke[Hecke$m_w=="w",] # female trap catches

barplot(m$trapcatch, ylab="Y", space=0.5, col=c("grey0"), ylim=c(0,450), las=2, cex.lab=0.9, cex.axis=0.9, cex.names=0.9)
barplot(w$trapcatch,space=0.5, add=TRUE, beside=FALSE, col=c("grey50"), xaxt="n", yaxt="n")

Thanks a lot
Sibylle
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: barplot_add=TRUE

Gerrit Eichner
Hi, Sibylle,

since you write '"mathematically" add', does

barplot(rbind(m$trapcatch, w$trapcatch))

do what you want (modulo layout details)?

  Hth  --  Gerrit

---------------------------------------------------------------------
Dr. Gerrit Eichner                   Mathematical Institute, Room 212
[hidden email]   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109            http://www.uni-giessen.de/eichner
---------------------------------------------------------------------

Am 09.01.2018 um 09:19 schrieb Sibylle Stöckli:

> Dear R users
>
> aim
> Barplot of insect trap catches (y variable trapcatch) at one specific station (variable FiBL_Hecke) from week 1-52 ( x variable week).
> It works well using the function tapply (sum trapcatch per week, males and females not separated), however, I intend to separate the y variable trapcatch in males and females (variable m_w: m and w)
>
> problem
> I used the function "add" to merge two bar plots (males and females). Unfortunately the second barplot masks the first barplot.
>
> question
> Is there a function to "mathematically" add the values from both barplots with the aim the barplot presenting the total trap (males and females) catches per week?
>
>
>
> Hecke<-trap[trap$station=="FiBL_Hecke",] # station = Hecke
> m<-Hecke[Hecke$m_w=="m",] # male trap catches
> w<-Hecke[Hecke$m_w=="w",] # female trap catches
>
> barplot(m$trapcatch, ylab="Y", space=0.5, col=c("grey0"), ylim=c(0,450), las=2, cex.lab=0.9, cex.axis=0.9, cex.names=0.9)
> barplot(w$trapcatch,space=0.5, add=TRUE, beside=FALSE, col=c("grey50"), xaxt="n", yaxt="n")
>
> Thanks a lot
> Sibylle
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: barplot_add=TRUE

Jim Lemon-4
In reply to this post by "Sibylle Stöckli"
Hi Sibylle,
I might have the wrong idea, but does this:

hecke<-matrix(sample(1:40,104,TRUE),nrow=2)
library(plotrix)
barp(hecke,col=c("lightblue","pink"))
legend(43,40,c("M","F"),fill=c("lightblue","pink"))

do what you want? It is also possible to display this as a nested bar
plot showing males and females within total catch.

Jim


On Tue, Jan 9, 2018 at 7:19 PM, Sibylle Stöckli <[hidden email]> wrote:

> Dear R users
>
> aim
> Barplot of insect trap catches (y variable trapcatch) at one specific station (variable FiBL_Hecke) from week 1-52 ( x variable week).
> It works well using the function tapply (sum trapcatch per week, males and females not separated), however, I intend to separate the y variable trapcatch in males and females (variable m_w: m and w)
>
> problem
> I used the function "add" to merge two bar plots (males and females). Unfortunately the second barplot masks the first barplot.
>
> question
> Is there a function to "mathematically" add the values from both barplots with the aim the barplot presenting the total trap (males and females) catches per week?
>
>
>
> Hecke<-trap[trap$station=="FiBL_Hecke",] # station = Hecke
> m<-Hecke[Hecke$m_w=="m",] # male trap catches
> w<-Hecke[Hecke$m_w=="w",] # female trap catches
>
> barplot(m$trapcatch, ylab="Y", space=0.5, col=c("grey0"), ylim=c(0,450), las=2, cex.lab=0.9, cex.axis=0.9, cex.names=0.9)
> barplot(w$trapcatch,space=0.5, add=TRUE, beside=FALSE, col=c("grey50"), xaxt="n", yaxt="n")
>
> Thanks a lot
> Sibylle
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: barplot_add=TRUE

"Sibylle Stöckli"
In reply to this post by Gerrit Eichner
Dear Gerrit

Thanks a lot. "rbind" seems to be the right function. Unfortunately there is a shift in the x-axis (see pdf). There are 52 trapcatch values each, m and w, but m$trapcatch and w$trapcatch are shifted up to x-value 60.
The follow-up lines for temp and humidity are fine.

Thanks
Sibylle






setwd("~/Desktop/DatenLogger2017")  #  am Mac sks
trap = read.delim("SWD_Trap_week-new.txt", na.strings="*", header=TRUE)  
climate = read.delim("Agrometeo_week-2017.txt", na.strings="*", header=TRUE)    
names(trap)
names(climate)


Hecke<-trap[trap$station=="FiBL_Hecke",]
m<-Hecke[Hecke$m_w=="m",]
w<-Hecke[Hecke$m_w=="w",]
par(mar=c(5,4,4,10))
barplot(rbind(m$trapcatch, w$trapcatch), ylim=c(0,350))
axis(1, 1:52)

par(new=T)
plot(climate$Week,climate$Frick_Temp.mittel, type="n", axes=F, ylim=c(0,25), ylab="", xlab="", xaxt="n")
lines(climate$Week, climate$Frick_Temp.mittel, lty=2, lwd=2, col="blue")
axis(4,las=1, cex.axis=0.8, col="blue")
mtext(side=4, line=2.5, "Mittlere Temperatur (°C)", cex=0.8, col="blue")

par(new=T)
plot(climate$Week,climate$Frick_Feuchte.mittel, type="n", axes=F, ylim=c(0,100), ylab="", xlab="", xaxt="n")
lines(climate$Week, climate$Frick_Feuchte.mittel, lty=2, lwd=2, col="darkgreen")
axis(4,las=1, line=5.5, cex.axis=0.8, col="darkgreen")
mtext(side=4, line=7.5, "Mittlere Feuchte (%)", cex=0.8, col="dark green")




Am 09.01.2018 um 09:30 schrieb Gerrit Eichner:

> Hi, Sibylle,
>
> since you write '"mathematically" add', does
>
> barplot(rbind(m$trapcatch, w$trapcatch))
>
> do what you want (modulo layout details)?
>
> Hth  --  Gerrit
>
> ---------------------------------------------------------------------
> Dr. Gerrit Eichner                   Mathematical Institute, Room 212
> [hidden email]   Justus-Liebig-University Giessen
> Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
> Fax: +49-(0)641-99-32109            http://www.uni-giessen.de/eichner
> ---------------------------------------------------------------------
>
> Am 09.01.2018 um 09:19 schrieb Sibylle Stöckli:
>> Dear R users
>> aim
>> Barplot of insect trap catches (y variable trapcatch) at one specific station (variable FiBL_Hecke) from week 1-52 ( x variable week).
>> It works well using the function tapply (sum trapcatch per week, males and females not separated), however, I intend to separate the y variable trapcatch in males and females (variable m_w: m and w)
>> problem
>> I used the function "add" to merge two bar plots (males and females). Unfortunately the second barplot masks the first barplot.
>> question
>> Is there a function to "mathematically" add the values from both barplots with the aim the barplot presenting the total trap (males and females) catches per week?
>> Hecke<-trap[trap$station=="FiBL_Hecke",] # station = Hecke
>> m<-Hecke[Hecke$m_w=="m",] # male trap catches
>> w<-Hecke[Hecke$m_w=="w",] # female trap catches
>> barplot(m$trapcatch, ylab="Y", space=0.5, col=c("grey0"), ylim=c(0,450), las=2, cex.lab=0.9, cex.axis=0.9, cex.names=0.9)
>> barplot(w$trapcatch,space=0.5, add=TRUE, beside=FALSE, col=c("grey50"), xaxt="n", yaxt="n")
>> Thanks a lot
>> Sibylle
>> [[alternative HTML version deleted]]
>> ______________________________________________
>> [hidden email] 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.
>>
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: barplot_add=TRUE

Gerrit Eichner
Dear Sibylle!

Am 09.01.2018 um 10:24 schrieb Sibylle Stöckli:
> Dear Gerrit
>
> Thanks a lot. "rbind" seems to be the right function. Unfortunately
> there is a shift in the x-axis (see pdf). There are 52 trapcatch values
> each, m and w, but m$trapcatch and w$trapcatch are shifted up to x-value
> 60.
> The follow-up lines for temp and humidity are fine.

Hm, I'm not quite sure if you are asking another question here ... ;-)
But I assume you do.

However, without knowledge about the structure of Hecke or m,
respectively, in particular about their row numbers, it is impossible
to spot the cause of your "problem". I suggest you check the structure
of m:

str(m)

I suspect you'll see that the assumption of 52 trapcatch values is
somehow wrong.

  Hth  --  Gerrit

---------------------------------------------------------------------
Dr. Gerrit Eichner                   Mathematical Institute, Room 212
[hidden email]   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109            http://www.uni-giessen.de/eichner
---------------------------------------------------------------------

>
> Thanks
> Sibylle
>
>
>
>
>
>
>
> setwd("~/Desktop/DatenLogger2017") #  am Mac sks
> trap= read.delim("SWD_Trap_week-new.txt", na.strings="*", header=TRUE)
> climate= read.delim("Agrometeo_week-2017.txt", na.strings="*", header=TRUE)
> names(trap)
> names(climate)
>
>
> Hecke<-trap[trap$station=="FiBL_Hecke",]
> m<-Hecke[Hecke$m_w=="m",]
> w<-Hecke[Hecke$m_w=="w",]
> par(mar=c(5,4,4,10))
> barplot(rbind(m$trapcatch, w$trapcatch), ylim=c(0,350))
> axis(1, 1:52)
>
> par(new=T)
> plot(climate$Week,climate$Frick_Temp.mittel, type="n", axes=F,
> ylim=c(0,25), ylab="", xlab="", xaxt="n")
> lines(climate$Week, climate$Frick_Temp.mittel, lty=2, lwd=2, col="blue")
> axis(4,las=1, cex.axis=0.8, col="blue")
> mtext(side=4, line=2.5, "Mittlere Temperatur (°C)", cex=0.8, col="blue")
>
> par(new=T)
> plot(climate$Week,climate$Frick_Feuchte.mittel, type="n", axes=F,
> ylim=c(0,100), ylab="", xlab="", xaxt="n")
> lines(climate$Week, climate$Frick_Feuchte.mittel, lty=2, lwd=2,
> col="darkgreen")
> axis(4,las=1, line=5.5, cex.axis=0.8, col="darkgreen")
> mtext(side=4, line=7.5, "Mittlere Feuchte (%)", cex=0.8, col="dark green")
>
>
>
>
> Am 09.01.2018 um 09:30 schrieb Gerrit Eichner:
>
>> Hi, Sibylle,
>>
>> since you write '"mathematically" add', does
>>
>> barplot(rbind(m$trapcatch, w$trapcatch))
>>
>> do what you want (modulo layout details)?
>>
>> Hth  --  Gerrit
>>
>> ---------------------------------------------------------------------
>> Dr. Gerrit Eichner                   Mathematical Institute, Room 212
>> [hidden email]
>> <mailto:[hidden email]>   Justus-Liebig-University
>> Giessen
>> Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
>> Fax: +49-(0)641-99-32109 http://www.uni-giessen.de/eichner
>> ---------------------------------------------------------------------
>>
>> Am 09.01.2018 um 09:19 schrieb Sibylle Stöckli:
>>> Dear R users
>>> aim
>>> Barplot of insect trap catches (y variable trapcatch) at one specific
>>> station (variable FiBL_Hecke) from week 1-52 ( x variable week).
>>> It works well using the function tapply (sum trapcatch per week,
>>> males and females not separated), however, I intend to separate the y
>>> variable trapcatch in males and females (variable m_w: m and w)
>>> problem
>>> I used the function "add" to merge two bar plots (males and females).
>>> Unfortunately the second barplot masks the first barplot.
>>> question
>>> Is there a function to "mathematically" add the values from both
>>> barplots with the aim the barplot presenting the total trap (males
>>> and females) catches per week?
>>> Hecke<-trap[trap$station=="FiBL_Hecke",] # station = Hecke
>>> m<-Hecke[Hecke$m_w=="m",] # male trap catches
>>> w<-Hecke[Hecke$m_w=="w",] # female trap catches
>>> barplot(m$trapcatch, ylab="Y", space=0.5, col=c("grey0"),
>>> ylim=c(0,450), las=2, cex.lab=0.9, cex.axis=0.9, cex.names=0.9)
>>> barplot(w$trapcatch,space=0.5, add=TRUE, beside=FALSE,
>>> col=c("grey50"), xaxt="n", yaxt="n")
>>> Thanks a lot
>>> Sibylle
>>> [[alternative HTML version deleted]]
>>> ______________________________________________
>>> [hidden email] <mailto:[hidden email]> 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.
>>>
>>
>> ______________________________________________
>> [hidden email] <mailto:[hidden email]> 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.
>

______________________________________________
[hidden email] 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.