使用geom_boxplot绘制基本的箱线图: library(ggplot2) ggplot(ToothGrowth, aes(x=dose, y=len)) + geom_boxplot() 1. 2. 3. 4. 2,设置离群点(outlier) geom_boxplot函数中有outlier开头的多个参数,用于修改离群点的属性: outlier.colour:离群点的颜色 outlier.fill:离群点的填充色 outlier.shape:离...
p <- ggplot(.,mapping = aes(spray,count)) p1 <- p + geom_boxplot(outlier.shape = 21,outlier.colour = "red",outlier.fill = "blue", col = "black",fill = brewer.pal(6,"Set1")) p2 <- p + stat_boxplot(geom = "errorbar",width=0.3)+ geom_boxplot(outlier.shape = 21,outlie...
p <- ggplot(data=employee,aes(x=jobcat,y=salary))p+geom_boxplot() 给不同分组按照不同职位类别类填充颜色加以区分。 p+geom_boxplot(aes(fill=jobcat)) 添加图标题和横纵轴标题。 p+geom_boxplot(aes(fill=jobcat))+labs(title="不同职位类别薪资分布",x="职位类别", y = "当前薪资") 3.散...
ggplot(mpg, aes(class, hwy)) + geom_boxplot(outlier.shape = NA)# 不显示异常值 ggplot(mpg, aes(class, hwy)) + geom_boxplot(aes(colour = drv)) 2.x是连续变量 ggplot(diamonds, aes(carat, price)) + geom_boxplot(aes(group = cut_width(carat, 0.25)),# 设置等宽分组 outlier.alpha =...
grid.arrange(bp,#bar plot spaning two columnsbxp, sp,#box plot amd scatter plotncol=2, nrow=2, layout_matrix=rbind(c(1, 1), c(2, 3))) 要相对grid.arrange()以及arrangeGrob()的输出进行注释,首先要利用as_ggplot()将其转化为ggplot图形,进而利用函数draw_plot_label()对其进行注释。
ggplot2 作图 代码语言:javascript 复制 library(ggplot2)library(stringr)library(ggprism)x_level<-paste(df$Group1,df$Group2,sep="_")x_level df1$group<-str_sub(df1$new_col,5,7)df1$new_col<-factor(df1$new_col,levels=x_level)ggplot(df1,aes(x=new_col,y=value))+stat_boxplot(geom="err...
ggplot(heightweight,aes(sex,heightIn))+geom_boxplot(aes(as.numeric(sex)-0.2,group=sex),width=.25)+geom_dotplot(aes(as.numeric(sex)+0.2,group=sex),binaxis="y",binwidth=0.5,stackdir="center")+scale_x_continuous(breaks=1:nlevels(heightweight$sex),labels=levels(heightweight$sex)) 13.X...
设为因子型:water$var<-factor(water$var,levels=c("TOC","DO"))类似于这样。R语言 | ggplot2...
df$x_factor<-factor(df$x_factor,levels=as.character(x_order$x_factor),ordered = TRUE) 参考文档: ggplot2 box plot : Quick start guide - R software and data visualization A box and whiskers plot (in the style of Tukey) MBA lib 箱线图...
boxplot可以在ggplot(aes(fill = ...))中设置箱子填充情况,也可以在geom_boxplot(aes(fill = ...))中设置。如下两个代码Output图是一样的。 # 注意所有的分类变量要做成factorToothGrowth$dose=as.factor(ToothGrowth$dose)ggplot(data=ToothGrowth,aes(x=dose,y=len,fill=supp))+geom_boxplot()+scale_fill...