【发布时间】:2021-11-08 08:29:57
【问题描述】:
我有一个数据集 AIS_dat,它查看在 Covid 锁定之前和期间一周中不同天 (Day) 的三个站点 (Site) 的船只数量 (BoatCount)。
rm(list = ls())
setwd('K:/SoundTrap/Boats/PSD Output/Duty cycle data/TOL analysis')
getwd()
AIS_dat<-read.csv("AllSitesConcat_dBcalcs_50-24000Hz_matchedCameraCounts.csv")
str(AIS_dat)
#set factors
AIS_dat$Lockdown <- as.factor(AIS_dat$Lockdown)
#change order of sites
AIS_dat$Site<-factor(AIS_dat$Site,
level=c('Kawau','Tiritiri','Noises'))
#change order of days
AIS_dat$Day<-factor(AIS_dat$Day,
level=c('Mon','Tue','Wed','Thu','Fri','Sat','Sun'))
#hour of day as factor
AIS_dat$Hour <- as.factor(AIS_dat$Hour)
#Look at variation between sites
bp<-ggplot(AIS_dat, aes(x=Day,y=BoatCount,fill=factor(Site))) +
geom_boxplot()+
ylab(expression("Number of Boats"))+
xlab("Day of Week")+
scale_fill_manual(values = get_pal("Kereru"),
name="Site") +
theme_bw()
bp
bp<-bp+theme(axis.text.x = element_text(angle = 0,size=14),
axis.text.y = element_text(size=14),
axis.title.x = element_text(size=14),
axis.title.y =element_text(size=14),
#legend.title = element_text(size = 14),
#legend.text = element_text(size = 14)
) #rotate x-axis labels
bp<-bp+facet_grid(rows=vars(Lockdown)) #separate plot for each season
bp
情节看起来像this
...太棒了。但是,因为在“期间”下没有 Tiritiri 的数据,我们只看到两个站点,并且随着站点的顺序发生变化,这有点误导。我想在此面板中缺少数据,以明确哪个站点是哪个站点。我该怎么做?我是否必须以某种方式将丢失的数据添加到我的原始数据表中?我试过了,但没有用,所以如果这是最好的方法,我不确定用哪种方法?
数据集看起来像 this(但有 17143 行):
【问题讨论】:
-
请修剪您的代码,以便更容易找到您的问题。请按照以下指南创建minimal reproducible example。
标签: r ggplot2 boxplot missing-data