Skip to content

Commit

Permalink
v2.0.4
Browse files Browse the repository at this point in the history
Updated 'trs' to support time column name with spaces.
Updated 'geom_ts' to modify spindle sub-axis range.
Fixed 'geom_ts' to fix the problem that the data frame names of spindle and sub-axis control are renamed with other data frames.
Tried to fix the problem of reading particle size data in vignette.
  • Loading branch information
tianshu129 committed Apr 5, 2022
1 parent df4bb6b commit 21e38c9
Show file tree
Hide file tree
Showing 19 changed files with 435 additions and 33 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: foqat
Type: Package
Title: Field Observation Quick Analysis Toolkit
Version: 2.0.3
Version: 2.0.4
Author: Tianshu Chen
Maintainer: Tianshu Chen <[email protected]>
Description: Tools for quickly processing and analyzing
Expand Down
2 changes: 2 additions & 0 deletions R/dm8n.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#' statistics of the number of effective 8-hour average concentrations in each day, maximum-8-hour ozone) and 1 plot (dma8 plot).
#' @export
#' @examples
#' \dontrun{
#' dm8n(aqi,colio=6,unitlb=c("NO (ppbv)", "NO2 (ppbv)", "CO (ppbv)", "SO2 (ppbv)", "O3 (ppbv)"))
#' }
#' @import lubridate
#' @importFrom stats aggregate
#' @importFrom utils stack unstack
Expand Down
2 changes: 2 additions & 0 deletions R/geom_avri.r
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
#'
#' @export
#' @examples
#' \dontrun{
#' x=avri(aqi, bkip = "1 hour", mode = "recipes", value
#' = "day", st = "2017-05-01 00:00:00")
#' geom_avri(x,cave=6, csd=11, alpha=0.5, lcc="#0050b3",
#' rff="#40a9ff", xlab="Time",ylab=bquote(O[3]~" "~(ppbv)))
#' }
#' @importFrom lubridate is.timepoint

geom_avri<-function(df,cave=2, csd=3, ssd=1, alpha=0.5, xlab=NULL, ylab=NULL, lcc=NULL, lsize=1, rff=NULL){
Expand Down
2 changes: 2 additions & 0 deletions R/geom_avri_batch.r
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#'
#' @export
#' @examples
#' \dontrun{
#' #example 1
#' x=avri(aqi, bkip = "1 hour", mode = "recipes", value
#' = "day", st = "2017-05-01 00:00:00")
Expand All @@ -37,6 +38,7 @@
#' ylab2=c("NO","NO2","CO","SO2","O3")
#' geom_avri_batch(x, alpha=0.6, xlab=xlab2, ylab=ylab2,
#' lcc=lcc, rff=rff, bquote=FALSE)
#' }
#' @importFrom lubridate is.timepoint
#' @import patchwork

Expand Down
39 changes: 18 additions & 21 deletions R/geom_ts.r
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
#' @param yl_minor_breaks a numeric vector of positions for minor breaks in left y axis.
#'
#' @export
#' @examples
#' @examples
#' \dontrun{
#' aqi2=aqi
#' aqi2$NO[aqi2$NO>7]=NA
#' aqi2$NO2=aqi2$NO2*0.3
Expand All @@ -52,6 +53,7 @@
#' lcc="#ff4d4f",
#' aff=c("#096dd9","#69c0ff"),
#' xlab="Datetime")
#' }
#' @importFrom reshape2 melt
#' @importFrom ggplot2 ggplot geom_area geom_bar geom_point geom_line scale_fill_discrete scale_fill_manual scale_linetype_manual scale_color_discrete scale_color_manual scale_shape_manual scale_y_continuous scale_x_datetime theme
#' @importFrom ggnewscale new_scale_color new_scale_fill
Expand Down Expand Up @@ -86,7 +88,7 @@ yl_breaks= waiver(), yr_breaks= waiver(), yl_minor_breaks = waiver()){
if(length(intersect(alist,yl))==1){
yla=intersect(alist,yl)
df[,yla][df[,yla]>yl_limit[2]]=NA#upper
df[,yla][df[,yla]<yl_limit[1]]=NAlower
df[,yla][df[,yla]<yl_limit[1]]=NA#lower
}else{
yla=intersect(alist,yl)
df[which(rowSums(df[,yla], na.rm=TRUE)>yl_limit[2]),yla]=NA#upper
Expand Down Expand Up @@ -356,7 +358,6 @@ yl_breaks= waiver(), yr_breaks= waiver(), yl_minor_breaks = waiver()){
if(length(llab)==0){llab=names(df)[llist]}
labs=setNames(llab,names(df)[llist])

##判断线型需求
##判断线型需求
if(length(ltype)!=0){
p = p + scale_linetype_manual(values=ltype, labels=labs)
Expand Down Expand Up @@ -388,9 +389,9 @@ yl_breaks= waiver(), yr_breaks= waiver(), yl_minor_breaks = waiver()){
###因子排序
df_yl_plist$variable=factor(df_yl_plist$variable,levels=fc_yl_plist)
if(length(pshape)==0){
p=p+geom_point(data=df_yl_plist, aes(x=df_yl_plist[,1], y=value, color=variable), size=lsize)
p=p+geom_point(data=df_yl_plist, aes(x=df_yl_plist[,1], y=value, color=variable), size=psize)
}else{
p=p+geom_point(data=df_yl_plist, aes(x=df_yl_plist[,1], y=value, color=variable, shape=variable), size=lsize)
p=p+geom_point(data=df_yl_plist, aes(x=df_yl_plist[,1], y=value, color=variable, shape=variable), size=psize)
}
}

Expand All @@ -407,15 +408,12 @@ yl_breaks= waiver(), yr_breaks= waiver(), yl_minor_breaks = waiver()){
###因子排序
df_yr_plist$variable=factor(df_yr_plist$variable,levels=fc_yr_plist)
if(length(pshape)==0){
p=p+geom_point(data=df_yr_plist, aes(x=df_yr_plist[,1], y=(value-yr_limit[1])*ryl/ryr+yl_limit[1], color=variable), size=lsize)
p=p+geom_point(data=df_yr_plist, aes(x=df_yr_plist[,1], y=(value-yr_limit[1])*ryl/ryr+yl_limit[1], color=variable), size=psize)
}else{
p=p+geom_point(data=df_yr_plist, aes(x=df_yr_plist[,1], y=(value-yr_limit[1])*ryl/ryr+yl_limit[1], color=variable, shape=variable), size=lsize)
p=p+geom_point(data=df_yr_plist, aes(x=df_yr_plist[,1], y=(value-yr_limit[1])*ryl/ryr+yl_limit[1], color=variable, shape=variable), size=psize)
}
}

#if(!exists("yl_plist")){yl_plist=NULL}
#if(!exists("yr_plist")){yr_plist=NULL}

##限制legend
if(length(plab)==0){plab=names(df)[plist]}
labs=setNames(plab,names(df)[plist])
Expand All @@ -426,7 +424,6 @@ yl_breaks= waiver(), yr_breaks= waiver(), yl_minor_breaks = waiver()){
}

##判断颜色需求

if(length(pcc)==0){
p = p + scale_color_discrete(labels=labs)
}else{
Expand All @@ -442,14 +439,14 @@ yl_breaks= waiver(), yr_breaks= waiver(), yl_minor_breaks = waiver()){
p=p+new_scale_color()+new_scale_fill()

###从df取上下限子数据集
df_yl_plist=df[,c(names(df)[1],"yl_up","yl_down")]
df_yl_plist_axis=df[,c(names(df)[1],"yl_up","yl_down")]
###为因子排序提前提取交集物种名
fc_yl_plist=names(df_yl_plist)[-1]
fc_yl_plist_axis=names(df_yl_plist_axis)[-1]
###子数据集变形以供画图
df_yl_plist=melt(df_yl_plist, id.vars = names(df_yl_plist)[1])
df_yl_plist_axis=melt(df_yl_plist_axis, id.vars = names(df_yl_plist_axis)[1])
###因子排序
df_yl_plist$variable=factor(df_yl_plist$variable,levels=fc_yl_plist)
p=p+geom_point(data=df_yl_plist, alpha = 0, aes(x=df_yl_plist[,1], y=value))
df_yl_plist_axis$variable=factor(df_yl_plist_axis$variable,levels=fc_yl_plist_axis)
p=p+geom_point(data=df_yl_plist_axis, alpha = 0, aes(x=df_yl_plist_axis[,1], y=value))
}

#副轴范围控制#################################
Expand All @@ -460,14 +457,14 @@ yl_breaks= waiver(), yr_breaks= waiver(), yl_minor_breaks = waiver()){
p=p+new_scale_color()+new_scale_fill()

###从df取上下限子数据集
df_yr_plist=df[,c(names(df)[1],"yr_up","yr_down")]
df_yr_plist_axis=df[,c(names(df)[1],"yr_up","yr_down")]
###为因子排序提前提取交集物种名
fc_yr_plist=names(df_yr_plist)[-1]
fc_yr_plist_axis=names(df_yr_plist_axis)[-1]
###子数据集变形以供画图
df_yr_plist=melt(df_yr_plist, id.vars = names(df_yr_plist)[1])
df_yr_plist_axis=melt(df_yr_plist_axis, id.vars = names(df_yr_plist_axis)[1])
###因子排序
df_yr_plist$variable=factor(df_yr_plist$variable,levels=fc_yr_plist)
p=p+geom_point(data=df_yr_plist, alpha = 0, aes(x=df_yr_plist[,1], y=(value-yr_limit[1])*ryl/ryr+yl_limit[1]))
df_yr_plist_axis$variable=factor(df_yr_plist_axis$variable,levels=fc_yr_plist_axis)
p=p+geom_point(data=df_yr_plist_axis, alpha = 0, aes(x=df_yr_plist_axis[,1], y=(value-yr_limit[1])*ryl/ryr+yl_limit[1]))
}

if(length(yr)!=0){
Expand Down
2 changes: 2 additions & 0 deletions R/geom_ts_batch.r
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#'
#' @export
#' @examples
#' \dontrun{
#' #example 1
#' geom_ts_batch(aqi)
#' #example 2
Expand All @@ -56,6 +57,7 @@
#' "~(ppbv)), bquote(O[3]~" "~(ppbv)))
#' cclist=c("#eb2f96", "#1890ff", "#52c41a", "#faad14", "#f5222d")
#' geom_ts_batch(aqi, xlab=xlab2, ylab=ylab2, cclist=cclist, bquote=TRUE)
#' }
#' @importFrom scales hue_pal
#' @import patchwork
#' @importFrom ggplot2 theme
Expand Down
3 changes: 3 additions & 0 deletions R/trs.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ trs <- function(df, bkip, st = NULL, et = NULL, fun = 'mean', probs=0.5, na.rm =
#set colnames of df
colnames(df) <- cona_df

#temp replace first colname
colnames(df)[1]="temp_datetime"

#get time zone of datetime
tzlc=attr(df[,1],"tzone")

Expand Down
10 changes: 0 additions & 10 deletions R/zzz.R

This file was deleted.

Binary file removed img/donation.png
Binary file not shown.
Binary file removed img/foqat_user_group.png
Binary file not shown.
Binary file removed img/logo.png
Binary file not shown.
Binary file removed img/wechat.png
Binary file not shown.
Loading

0 comments on commit 21e38c9

Please sign in to comment.