Resumen del código de dibujo en lenguaje R

Gráfico de barras

Gráfico de barras ordinario

ggplot(df,],aes(x=group,y=value))
+geom_bar(stat = "identity",width = 0.57) #width是条形宽度
+theme_bw() #去掉灰色的背景
+scale_x_discrete(labels=c("AUC-B","AUC-P")) #x轴分组的标签
+labs(x="time",y="AUC") #x轴和y轴的标签
+theme(title = element_text(size=24),axis.text= element_text(size=16))
# title控制xy轴的标题字体大小,axis.text是轴分组标签的字体大小

Imagen de efecto:
Inserte la descripción de la imagen aquí

Gráfico de barras agrupadas agrupadas

ggplot(df,aes(x=group,y=value,fill=group2))
+geom_bar(stat = "identity",position = position_dodge(0.7),width = 0.7)
#position_dodge是并排而不是堆积条形图参数的0.7是簇内条形间距,width是条形宽度
+scale_fill_grey(start=0.7,end=0.4,labels=c("AUC-B","AUC-P"))
#fill_grey是灰度,后面的start和end是灰度百分比,labels显示在图例上
#想用彩色可以用 scale_fill_brewer()
+theme_bw() #去灰色背景
+scale_x_discrete(labels=c("<80%","80-90%","90-97%","97-100%"))
#改变x轴分组的标签
+labs(x="TIR",y="AUC") #改变x和y轴的标签
+theme(legend.position = c(0.9,0.9)) #图例位置,c(1,1)是右上角,c(0,0)是原点
+guides(fill=guide_legend(title=NULL)) #改变图例标题,NULL就是取消标题

Imagen de efecto:
Inserte la descripción de la imagen aquí

Supongo que te gusta

Origin blog.csdn.net/Alleine/article/details/108089303
Recomendado
Clasificación