#默认分组设置,即group=1p+geom_boxplot()#分组(group)也是ggplot2种映射关系的一种,如果需要把观测点按额外的离散变量进行分组处理,必须修改默认的分组设置。 p1<-ggplot(data=diamond,mapping=aes(x=carat,y=price,group=factor(cut)))p1+geom_boxplot() 注意:不同的几何对象,要求的属性会有些不同,这些属...
ggplot2软件包的stat_summary是可以可以直接实现添加误差线的。 1 2 3 4 ggplot(data_m,aes(x=Group, y=TB, fill = Salinity)) + stat_summary(fun = mean, geom ="bar", position =position_dodge(0.9), color ="black") + stat_summary(fun.data = mean_se, geom ="errorbar", position =posi...
ggplot(df,aes(group1,value))+ stat_boxplot(aes(color=group1),geom="errorbar",width=0.1,size=0.8,linetype=2)+ geom_boxplot(aes(fill=group1),outlier.color=NA,color=NA)+ stat_summary(fun=median,geom="point",size=3,shape=21,color="black",fill="white") 9、有缺口箱线图: ggplot(df...
ggplot(df,aes(group1,value))+ geom_bar(aes(fill=group1),stat="summary",fun=mean,position="dodge")+ geom_point(color="black",size=2.5) #geom_jitter() ggplot(df,aes(group1,value))+ geom_bar(aes(fill=group1),stat="summary",fun=mean,position="dodge")+ geom_jitter(color="black",s...
breaks=seq(70,170,by=20), limits=c(0,200), guide = guide_legend()) #help("scale_fill_gradient") #2.7在不同x上计算y值:stat = "summary" #例:既可以显示原始数据又可以展示均值 ggplot(mpg,aes(trans,cty))+ geom_point()+ geom_point(stat = "summary",fun.y="mean",colour="red",siz...
1 stat_summary 要求数据源的y能够被分组,每组不止一个元素, 或增加一个分组映射,即aes(x= , y = , group = ) library(Hmisc) g <- ggplot(mtcars,aes(cyl, mpg)) + geom_point() #mean_cl_bool对mpg进行运算,返回均值,最大值,最小值;其他可用smean.cl.normal,smean.sdl,smedian.hilow。
iris %>% pivot_longer(-Species) %>% filter(Species !="versicolor") %>% mutate(group=str_sub(name,start = 1, end = 5)) %>% ggplot(.,aes(x =name , y = value)) + stat_summary(geom = "bar",position = "dodge",aes(fill=Species)) + stat_summary(geom = "errorbar",fun.data...
stat_summary(mapping = NULL, data = NULL, geom = "pointrange", position = "identity", ..., fun.data = NULL, fun.y = NULL, fun.ymax = NULL, fun.ymin = NULL, fun.args = list(), na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) ...
幸运的是,ggplot2的开发人员已经考虑了如何深入可视化统计信息的问题。解决方案是使用 stat_summary 函数。我们将使用 gapminder 数据集,其中包含有不同国家/地区人们的预期寿命的数据。如图所见,近几十年来预期寿命有所增加。但是,条形图并未显示所有国家的平均预期寿命或中位数预期寿命,而是把每个国家...
1 stat_summary 要求数据源的y能够被分组,每组不止一个元素, 或增加一个分组映射,即aes(x= , y = , group = ) library(Hmisc) g <- ggplot(mtcars,aes(cyl, mpg)) + geom_point() #mean_cl_bool对mpg进行运算,返回均值,最大值,最小值;其他可用smean.cl.normal,smean.sdl,smedian.hilow。