R ggplot无线电跟踪周期
这是我在StackOverflow的第一个问题,所以请告诉我,如果我在发布过程中犯了一些错误,我会尽快编辑这个问题 我是ggplot2新手,我想用这个软件包绘制无线电跟踪周期。我的数据包括在两个不同年份(2011-2012年)的活动季节(从2005年15月15日到2009年15月15日)内以不均匀间隔采集的动物坐标位置(VHF类型数据) 我想做的是展示每一个人在其一年的活跃季节中以尽可能最好的方式被无线电跟踪的程度 我知道这听起来很复杂,所以我举了一个例子来说明我的意思,以及我到目前为止能够实现的目标。 “掉落”一栏表示发射器从动物身上掉落并随后重新连接,这也意味着在没有发射器的时间跨度内,无法对动物进行无线电跟踪R ggplot无线电跟踪周期,r,ggplot2,R,Ggplot2,这是我在StackOverflow的第一个问题,所以请告诉我,如果我在发布过程中犯了一些错误,我会尽快编辑这个问题 我是ggplot2新手,我想用这个软件包绘制无线电跟踪周期。我的数据包括在两个不同年份(2011-2012年)的活动季节(从2005年15月15日到2009年15月15日)内以不均匀间隔采集的动物坐标位置(VHF类型数据) 我想做的是展示每一个人在其一年的活跃季节中以尽可能最好的方式被无线电跟踪的程度 我知道这听起来很复杂,所以我举了一个例子来说明我的意思,以及我到目前为止能够实现
library(ggplot2)
library(scales)
##transform the data for ggplot
traj$Date<-as.Date(as.character(traj$Date),"%Y%m%d")
traj$Date<-as.POSIXct(traj$Date)
traj$Year<-as.factor(traj$Year)
##plot graph
inf<-as.POSIXct(as.Date('20110515',format="%Y%m%d"))
sup<-as.POSIXct(as.Date('20110915',format="%Y%m%d"))
direplot <- ggplot(traj, aes(x=Date, y=Name,colour=Year,drop=TRUE)) +
geom_point()+
labs(title="Radiotracking scheme",x="Month")+
scale_x_datetime(limits=c(inf,sup),breaks = date_breaks("1 month"),labels=date_format("%b"))+
facet_grid(Sex~.,scales="free",drop=TRUE)+guides(size=FALSE)
direplot
库(ggplot2)
图书馆(比例尺)
##将数据转换为ggplot
traj$Date试试:
@agstudy-我刚刚将其回滚。为什么年份栏与日期栏的年份部分不同?@agstudy嗨!因为否则数据会在两年内显示出来(至少是这样),我需要对动物进行比较(即使它们在两个不同的季节进行了无线电跟踪)。也许有一种更优雅的方式,但统一日期已经足够有效了:——)@Vagabond_20但你如何获得第二个情节?@agstudy我刚刚发布的是第一个情节的gimp编辑版本(看起来不太“专业”),它代表了我想在R中获得的东西(我不知道它是否切实可行)。@mso嗨!谢谢你的贡献!ifelse()+geom_bar()思想值得探索。不幸的是,在这个过程中,年份因素似乎必须被删除。年份应该是日期的一部分。如果你想要季节性的变化,可以把日期和月份的值放在一列,也可以只放在月份。
dires<- "Name Date Sex Year Dropped
1 Nymeria 20110603 Female 2011 no
2 Nymeria 20110604 Female 2011 no
3 Nymeria 20110605 Female 2011 no
4 Nymeria 20110606 Female 2011 no
5 Nymeria 20110607 Female 2011 no
6 Nymeria 20110609 Female 2011 no
7 Nymeria 20110610 Female 2011 yes
8 Nymeria 20110811 Female 2011 no
9 Nymeria 20110812 Female 2011 no
10 Nymeria 20110816 Female 2011 no
11 Nymeria 20110817 Female 2011 no
12 Nymeria 20110818 Female 2011 no
13 Nymeria 20110825 Female 2011 yes
14 Ghost 20110518 Male 2011 no
15 Ghost 20110520 Male 2011 no
16 Ghost 20110521 Male 2011 yes
17 Ghost 20110609 Male 2011 no
18 Ghost 20110610 Male 2011 no
19 Ghost 20110612 Male 2011 no
20 Ghost 20110619 Male 2011 no
21 Ghost 20110620 Male 2011 no
22 Ghost 20110621 Male 2011 no
23 Ghost 20110622 Male 2011 no
24 Ghost 20110704 Male 2011 no
25 Ghost 20110721 Male 2011 no
26 Ghost 20110725 Male 2011 yes
27 Grey_wind 20110515 Male 2012 no
28 Grey_wind 20110516 Male 2012 no
29 Grey_wind 20110524 Male 2012 no
30 Grey_wind 20110610 Male 2012 no
31 Grey_wind 20110611 Male 2012 no
32 Grey_wind 20110614 Male 2012 no
33 Grey_wind 20110615 Male 2012 no
34 Grey_wind 20110630 Male 2012 yes
35 Grey_wind 20110721 Male 2012 no
36 Grey_wind 20110725 Male 2012 no
37 Grey_wind 20110726 Male 2012 no
38 Grey_wind 20110727 Male 2012 no
39 Grey_wind 20110731 Male 2012 yes
40 Lady 20110515 Female 2012 no
41 Lady 20110516 Female 2012 no
42 Lady 20110530 Female 2012 no
43 Lady 20110610 Female 2012 no
44 Lady 20110613 Female 2012 no
45 Lady 20110614 Female 2012 no
46 Lady 20110615 Female 2012 yes
47 Lady 20110727 Female 2012 no
48 Lady 20110731 Female 2012 no
49 Lady 20110802 Female 2012 no
50 Lady 20110808 Female 2012 no
51 Lady 20110809 Female 2012 no
52 Lady 20110811 Female 2012 yes"
traj <- read.table(text=dires, header = TRUE)
traj$Tracked = ifelse(traj$Dropped=='yes',0,1)
ggplot(traj, aes(x=Date, y=Tracked, fill=Sex ))+geom_bar(stat='identity', position='dodge')+facet_grid(Name~.)+scale_y_continuous(breaks=c(0,1))