Re: [R] Circular plot - polar plot code questions
Thanks yo Tim and Jim for useful suggestions re: my query on circular plots. Rethinking my goal, it appears Jim's suggestion of alternative linear plots make more sense and likley more intuitive for reader. Bruce __ R-help@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] Circular plot - polar plot code questions
Hi all... I assume there are a host of GGplot2 users out there. I have circular plot - polar plot code questions I needed to create circular – polar plots of reproductive status for bats. I found a great sample of how to do this here: https://stackoverflow.com/questions/41081376/how-to-create-a-circular-plot-showing-monthly-presence-or-absence-using-radial-p I modified the sample code to meet the 3 data elements I am using the "raw data" table below with T=testes enlarge, P= Pregnant and L= Lactating. library(data.table) m <- fread("id T month P L 1 0 1 0 0 2 0 2 0 0 3 0 3 0 0 4 1 4 0 0 5 1 5 1 0 6 1 6 1 1 7 0 7 1 1 8 0 8 1 1 9 0 9 0 1 10 0 10 0 0 11 0 11 0 0 12 0 12 0 0") # reshape from wide to long (as preferred by ggplot) ml <- melt(m, measure.vars = c("T", "P", "L")) # create factors to ensure desired order ml[, variable := factor(variable, levels = c("T", "P","L"))] ml[, fct_month := factor(month, levels = 1:12, labels = month.abb)] library(ggplot2) ggplot(ml[value != 0], aes(x = fct_month, y = variable, group = variable, colour = variable)) + geom_line(size = 3) + scale_y_discrete(expand = c(0, 1), breaks = NULL) + xlim(month.abb) + coord_polar() + theme_bw() + xlab(NULL) + ylab(NULL) This is creating a plot more or less as needed. 4 questions: 1 Do I even need the ID field? Seems not useful. 2 I assume the melt step can be avoided if my data is "Tidy" and long format at the start, correct? 3 How can I increase the weight of the month lines and labels 4 Where can I add color choices for the 3 variables in the plot? Simply adding an HTML color number to the “colour=variable” then plots the data and labeling one value as that color. Tnx all. The list is always educational on a daily basis. Cheers, Bat Dude [[alternative HTML version deleted]] __ R-help@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] How to replace NA values
Hi all, I am using reshape2 to reformat a data frame and all is great using: Bats.melt - melt(data = Bats) Bats.cast - dcast(data = Bats.melt, formula = Species ~ Location) dput(Bats.cast,'C:/=Bat data working/Nica_new/Bats_niche.robj') write.csv(Bat.cast,'C:/=Bat data working/Nica_new/test_Niche.csv') The resulting file from both dput and write are great, however in order to run another R analysis I need to replace all the NA values in the output with a zero - 0 value. I have just been opening this in Excel and using a simple find NA replace with 0 and saving then reopening in R. There must be a simple way to do this in R. Any suggestions welcomed. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] reshape2 issue
Hi all, I am revisiting using reshape2 to aggregate critter (bats) occurrences by time blocks and have the final output for each row sum a percentage such that the row sums total 1 (100%). Reshape2 library is loaded on start. The old code I had stored in NotePad++ seems to no longer work as I have the following error: input.cast - cast(input.melt, Species ~ Date, fun.aggregate = sum) *Error: could not find function cast* The code saved in NotePad++ is: require(reshape2) input.melt - melt(input) input.cast - cast(input.melt, Species ~ Date, fun.aggregate = sum) input.percent - input.cast[, -1] / rowSums(input.cast[, -1]) * 100 rownames(input.percent) - input.cast[,1] The data is read in OK: Escameca_temporal - read.table(C:/=Bat data working/=Nica_new/Escameca_temporal.CSV,header=T,sep=,,quote=) #then renamed : input -Escameca_temporal The variable view shows Species (6 letter text code) as Factor;Location code as integer; Date as Factor; Time as Factor. Data looks like this (sub sample only) Species LocationDateTime Cynmex 49375/3/201223:42 Cynmex 49375/3/201223:43 Cynmex 49375/3/201223:43 Eptfur 49375/2/20120:10 Eptfur 49375/2/20120:12 Eptfur 49375/2/20120:15 Eptfur 49375/2/20120:16 Eptfur 49375/2/20120:21 Eptfur 49375/2/20120:27 Eptfur 49375/2/20120:27 Eptfur 49375/2/20120:36 Eptfur 49375/2/20120:37 Eptfur 49375/2/20120:38 Eptfur 49375/2/20120:42 Eptfur 49375/2/20120:57 Eptfur 49375/2/20120:58 Eptfur 49375/2/20120:59 Eptfur 49375/2/20121:01 Eptfur 49375/2/20121:03 Eptfur 49375/2/20121:08 Eptfur 49375/4/20122:02 Eptfur 49375/4/20122:03 Eptfur 49375/4/20122:03 Eptfur 49375/4/20122:04 Eptfur 49375/4/20122:04 Eptfur 49375/4/20122:08 Eptfur 49241/8/20122:09 Eptfur 49375/4/20122:09 Eptfur 49241/8/20122:10 Eptfur 49241/8/20122:10 Eptfur 49241/8/20122:10 Eptfur 49241/8/20122:10 Eptfur 49241/8/20122:11 Eptfur 49241/8/20122:11 Eptfur 49241/8/20122:11 Eptfur 49241/8/20122:11 Eptfur 49241/8/20122:11 Eptfur 49241/8/20122:12 Eptfur 49241/8/20122:12 Eptfur 49241/8/20122:12 Eptfur 49241/8/20122:12 Eptfur 49241/8/20122:12 Eptfur 49241/8/20122:13 Eptfur 49241/8/20122:13 Eptfur 49375/4/20122:13 Eptfur 49241/8/20122:14 Eptfur 49241/8/20122:14 Eptfur 49241/8/20122:14 Eptfur 49241/8/20122:14 Eptfur 49375/4/20122:14 Eptfur 49241/8/20122:15 Eptfur 49241/8/20122:15 Eptfur 49241/8/20122:15 Eptfur 49241/8/20122:16 Eptfur 49241/8/20122:16 Eptfur 49241/8/20122:16 Eptfur 49241/8/20122:16 Eptfur 49241/8/20122:17 Any suggestions-help appreciated. Bruce [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] How does one set up logical functions?
Hi all, I am trying to set up logical function(s) to deal with two adjustments to a blood glucose value. I have been dinking around in Excel and assume this will be much easier in R. DF is date-time, BG value in mg/dL,test strip 4/3/13 19:20105 Aviva-491350 4/4/13 21:0374 Aviva-491350 4/6/13 17:4081 Aviva-491640 4/6/13 17:4082 Aviva-491350 4/6/13 22:48106 Aviva-491640 4/6/13 22:48102 Aviva-491350 4/7/13 5:32 87 Aviva-491350 4/7/13 5:32 103 Aviva-491640 What I need are the high and low ranges based on acceptable standards of the measured values. The logical expressions need to be IF BG =100 then High limit would = (BG+(BG*.15)) IF BG =100 then Low limit would = (BG-(BG*.15)) and IF BG 100 then High limit would = (BG+15) IF BG 100 then Low limit would = (BG-15) The standards are written as: 95% of the individual glucose results shall fall within ±15 mg/dL of the reference results at glucose concentrations less than 100 mg/dL and within ±15% at glucose concentrations greater than or equal to 100 mg/dL. Then I need to plot the measured value and also show the high low acceptable values. Thanks for any who respond. Bruce [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Reshape or Plyr?
H all, I have relative abundance data from 100 sites. This is from acoustic monitoring and usually the data is for 2-3 nights but in some cases my be longer like months or years for each location.. The data output from my management data base is proved by species by night for each location so data frame would look like this below. What I need to do is sum the Survey_time by Spec_Code for each location name and divide summed AI values for each Spec_code by the summed Survey time to adjust for unit effort then standardize it all by *10 to represent the relative abundance by survey hour to 10 hours. How best to do this? Using Plyr or reshape? Location name SPEC_CODE Start_Day Survey_Time AI Std AI 079-f2p1-AcetunaBuzz2/14/2012 12.11 0.8264463 079-f2p1-AcetunaBuzz2/14/2012 12.11 0.8264463 079-f2p1-AcetunaEumspp 2/14/2012 12.11 0.8264463 079-f2p1-AcetunaFrag2/14/2012 12.118 14.87603 079-f2p1-AcetunaMolspp 2/14/2012 12.15 4.132231 079-f2p1-AcetunaMolspp 2/14/2012 12.15 4.132231 079-f2p1-AcetunaPhyllo 2/14/2012 12.12 1.652893 079-f2p1-AcetunaPtedav 2/14/2012 12.11 0.8264463 079-f2p1-AcetunaPtegym 2/14/2012 12.11 0.8264463 079-f2p1-AcetunaPtepar 2/14/2012 12.12 1.652893 079-f2p1-AcetunaRhotum 2/14/2012 12.16 4.958678 079-f2p1-AcetunaSacbil 2/14/2012 12.16 4.958678 079-f2p1-AcetunaSaclep 2/14/2012 12.111 9.090909 079-f2p1-AcetunaBuzz2/15/2012 12.12 1.652893 079-f2p1-AcetunaBuzz2/15/2012 12.12 1.652893 079-f2p1-AcetunaMolmol 2/15/2012 12.11 0.8264463 079-f2p1-AcetunaMolspp 2/15/2012 12.17 5.785124 079-f2p1-AcetunaMolspp 2/15/2012 12.17 5.785124 079-f2p1-AcetunaNocalb 2/15/2012 12.16 4.958678 079-f2p1-AcetunaPhyllo 2/15/2012 12.11 0.8264463 079-f2p1-AcetunaPtedav 2/15/2012 12.11 0.8264463 079-f2p1-AcetunaPtegym 2/15/2012 12.14 3.305785 079-f2p1-AcetunaPtepar 2/15/2012 12.14 3.305785 079-f2p1-AcetunaPteper 2/15/2012 12.13 2.479339 079-f2p1-AcetunaRhotum 2/15/2012 12.17 5.785124 079-f2p1-AcetunaSacbil 2/15/2012 12.12 1.652893 079-f2p1-AcetunaSaclep 2/15/2012 12.16 4.958678 079-f2p1-AcetunaBuzz2/16/2012 12.21 0.8196721 079-f2p1-AcetunaBuzz2/16/2012 12.21 0.8196721 079-f2p1-AcetunaEumspp 2/16/2012 12.24 3.278688 079-f2p1-AcetunaMolspp 2/16/2012 12.22 1.639344 079-f2p1-AcetunaMolspp 2/16/2012 12.22 1.639344 079-f2p1-AcetunaMyokea 2/16/2012 12.21 0.8196721 079-f2p1-AcetunaNocalb 2/16/2012 12.24 3.278688 079-f2p1-AcetunaPhyllo 2/16/2012 12.21 0.8196721 079-f2p1-AcetunaPtedav 2/16/2012 12.21 0.8196721 079-f2p1-AcetunaPtegym 2/16/2012 12.21 0.8196721 079-f2p1-AcetunaPtepar 2/16/2012 12.23 2.459016 079-f2p1-AcetunaPteper 2/16/2012 12.21 0.8196721 079-f2p1-AcetunaRhotum 2/16/2012 12.217 13.93443 079-f2p1-AcetunaSacbil 2/16/2012 12.23 2.459016 079-f2p1-AcetunaSaclep 2/16/2012 12.215 12.29508 Thanks for any suggestions. Excel will be a mess to try to do that. Bruce [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Query on package to use for investment quotes
Hi all, Diverging from my research based number crunching I am interested to see what, if any R packages are out there that can access daily market values of investment funds (e.g. using http://quote.morningstar.com/fund/f.aspx?t=PDMIX) then store the data value (i.e. NAV =$11.56 ) with date retrieved so these can be plotted with ggplot2 on some regular basis. A web search turned up a confusing and complex array of R prediction models etc. but I am looking for plain vanilla way to retrieve fund values and store the values. Thanks, Bruce -- Bruce W. Miller, Ph.D. Conservation Ecologist Neotropical Bat Projects office details 11384 Alpine Road Stanwood, Mi. 49346 Phone (231) 679-6059 __ R-help@r-project.org mailing list 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] Are there any package for sub-sampling data
Hi all, I need to sub sample some large data sets. The problem is using complete data samples for bats that are ± data per 1-minute time blocks using acoustic data collection and a method I published some time back. Miller, B. W. 2001. A method for determining relative activity of free flying bats using a new activity index for acoustic monitoring. Acta Chiropterologica. 3: 93-105. I am convinced after analyzing complete data for each night to derive relative abundance and species compositions that the consultants who are doing wind power monitoring and ONLY using 5 to 10 minute sub samples for each hour like the first 5 or 10 minutes are missing especially eh rare species that have only a few occurrences so misleading results. Anyone have any suggestions to a field ecologists who is not a dyed in the wool stats person on how to sub sample the data sets and robustly test this hypothesis? Happy to co-author a paper if some one is interested as I have the data. Cheers, Bruce -- Bruce W. Miller, Ph.D. Conservation Ecologist Neotropical Bat Projects office details 11384 Alpine Road Stanwood, Mi. 49346 Phone (231) 679-6059 __ R-help@r-project.org mailing list 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] Reshape2 sytax
Hi Hadley et all, I am struggling with reshape2 and melt works and melt_check (filtered151) seems fine My cast command was acast (filtered151, Time ~ Species ~ Number) melt_check (filtered151) Using time, Species as id variables $id [1] timeSpecies $measure [1] Number When I execute cast the data matrix is in the correct order but the data values are not included. Clearly I am missing something. I expected / need to have the column values to = the values from the input data set for each time block. Morbla Ptemac Ptepar Ptequa 0:00 0 0 0 0 0:15 0 0 0 0 0:30 0 0 0 0 0:45 0 0 0 0 1:00 0 0 0 0 1:15 0 0 0 0 1:30 0 0 0 0 1:45 0 0 0 0 18:45 0 0 0 0 19:00 0 0 0 0 19:15 0 0 0 0 19:30 0 0 0 0 19:45 0 0 0 0 2:00 0 0 0 0 2:15 0 0 0 0 2:30 0 0 0 0 2:45 0 0 0 0 20:00 0 0 0 1 20:15 0 0 0 0 20:30 0 0 0 0 20:45 0 0 0 0 21:00 0 0 0 0 21:15 0 0 0 0 21:30 0 0 0 0 21:45 0 0 0 0 22:00 0 0 0 0 22:15 0 0 0 0 22:30 0 0 0 0 22:45 0 0 0 0 23:00 0 0 0 0 23:15 0 0 0 0 23:30 0 0 0 0 23:45 0 0 0 0 3:00 0 0 0 0 3:15 0 0 0 0 3:30 0 0 0 0 3:45 0 0 0 0 4:00 0 0 0 0 4:15 0 0 0 0 4:30 0 0 0 0 4:45 0 0 0 0 5:00 0 0 0 0 5:15 0 0 0 0 5:30 0 0 0 0 5:45 0 0 0 0 6:00 0 0 0 0 6:15 0 0 0 0 6:30 0 0 0 0 6:45 0 0 0 0 7:00 0 0 0 0 Data is in long format like this: TimeLabel Number 0:00Morbla 2 0:00Ptemac 27 0:00Ptequa 21 0:00Ptequa 1 0:15Morbla 3 0:15Morbla 1 0:15Ptemac 18 0:15Ptequa 49 0:30Morbla 2 0:30Ptemac 7 0:30Ptepar 0 0:30Ptequa 18 0:45Morbla 2 0:45Ptemac 26 0:45Ptepar 1 0:45Ptequa 12 1:00Morbla 4 1:00Ptemac 18 1:00Ptepar 0 1:00Ptequa 20 1:15Morbla 4 1:15Ptemac 5 1:15Ptepar 1 1:15Ptequa 16 ...etc Bruce -- Bruce W. Miller, Ph.D. Conservation Ecologist Neotropical Bat Project office details Gallon Jug, Belize Mailing address P.O. Box 37, Belize City Belize, Central America Phone +501-220-9002 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Anyone free to take a data format question for Reshape2?
I need to reformat long data into a wide format (matrix for another program) but it does not seem straight forward. Can not seem to get it to work since some data elements are strings. Anyone have time to look at the issue? Tnx Bruce -- Bruce W. Miller, Ph.D. Conservation Ecologist Neotropical Bat Project office details Gallon Jug, Belize Mailing address P.O. Box 37, Belize City Belize, Central America Phone +501-220-9002 __ R-help@r-project.org mailing list 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] Best package suggestion
Hi all, What is the best package to use to evaluate correlations between events by time (species co-occurrence). Chron? I would like to determine fi there is any solid relationship between the occurrence of critter A given critter B is present at a given time frame. Bruce __ R-help@r-project.org mailing list 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.