创建一个自定义主题
library(pacman)
pacman::p_load(tidyverse,ggsci,gghalves,reshape2)
theme_niwot <- function(){
theme_bw() +
theme(text = element_text(family = "Helvetica Light"),
axis.line.x = element_line(color="black"),
axis.line.y = element_line(color="black"),
axis.text.x = element_text(family = "Times",size=12),
axis.text.y = element_text(family = "Times",size=12),
panel.border = element_blank(),
axis.title.x = element_text(margin = margin(t = 10),size=13,
family = "Times",color="black"),
axis.title.y = element_text(margin = margin(r = 10),size=13,
family = "Times",color="black"),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
panel.grid.major.y = element_blank(),
plot.margin = unit(c(1, 1, 1, 1), units = ,"cm"),
legend.text = element_text(size = 12,family ="Times"),
legend.title = element_blank(),
legend.key = element_blank(),
panel.background = element_rect(fill = "white"),
legend.background = element_rect(color = "black",
fill = "transparent",size = 2, linetype = "blank"))
}
均值+标准误差
df <- iris %>% group_by(Species) %>%
summarize(mean=mean(Sepal.Length),sd=sd(Sepal.Length))
iris %>% ggplot(aes(Species,Sepal.Length,fill=Species))+
geom_half_violin(position = position_nudge(x = 0.25),side=2,alpha = 0.8)+
geom_point(aes(y=Sepal.Length, color = Species),
position = position_jitter(width = 0.15),
size = 1,alpha = 0.8)+
geom_pointrange(data=df,position = position_nudge(x = 0.3),
aes(y=mean,ymin=mean-sd,ymax=mean+sd))+
labs(y ="Sepal.Length", x = NULL) +
guides(fill = FALSE, color = FALSE) +
scale_color_npg()+scale_fill_npg()+
coord_flip()+theme_niwot()
boxplot
iris %>% ggplot(aes(Species,Sepal.Length,fill=Species))+
geom_half_violin(position = position_nudge(x = 0.2),side=2,alpha = 0.8)+
geom_point(aes(y=Sepal.Length, color = Species),
position = position_jitter(width = 0.15),
size = 1,alpha = 0.8)+labs(x=NULL)+
geom_boxplot(width = 0.1, outlier.shape = NA,alpha = 0.8)+
guides(fill = FALSE, color = FALSE) +
scale_color_npg()+scale_fill_npg()+coord_flip()+
theme_niwot()
网友评论