您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“R語(yǔ)言怎么實(shí)現(xiàn)柱形圖”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
df<-readxl::read_excel("example_data/001.xlsx")
head(df)
df
library(dplyr)
df%>%
group_by(group)%>%
summarise(mean_value=mean(value),sd_value=sd(value)) -> df1
df1
library(ggplot2)
ggplot(data=df1,aes(x=group,y=mean_value))+
geom_col(aes(fill=group))+
geom_errorbar(aes(ymin=mean_value-sd_value,
ymax=mean_value+sd_value),
width=0.2)+
theme_bw()+
scale_y_continuous(expand=c(0,0),limits=c(0,4),
breaks = c(0,1,2,3,4))+
scale_fill_manual(values=c("#1f78b4", "#33a02c", "#e31a1c"))
df<-read.csv("example_data/002.csv",header=T)
df
ggplot(data=df,aes(x=dose,y=len,fill=supp))+
geom_bar(stat="identity",position = "dodge",width=0.5)+
geom_errorbar(aes(ymin=len-sd_value,ymax=len+sd_value),width=0.2,
position = position_dodge(0.5))+
theme_bw()+
scale_fill_manual(values=c("#33a02c", "#e31a1c"))+
scale_y_continuous(expand = c(0,0),limits = c(0,40))
df%>%group_by(dose)%>%mutate(new_col=cumsum(len)) -> df1
df1
ggplot(data=df1,aes(x=dose,y=len,fill=supp))+
geom_bar(stat="identity",position="stack")+
geom_text(aes(label=len),
position = position_stack(vjust=0.5),color="white")+
geom_errorbar(aes(ymin=new_col-sd_value,ymax=new_col+sd_value),
width=0.1)+
theme_bw()+scale_fill_manual(values=c("#33a02c", "#e31a1c"))+
scale_y_continuous(expand = c(0,0),limits = c(0,70))
df<-read.csv("example_data/003-1.csv",header=T)
df
ggplot(data=df,aes(x=dose,y=len,group=1))+
geom_line()+geom_point()+
geom_errorbar(aes(ymin=len-sd_value,ymax=len+sd_value),width=0.05)+
theme_bw()+
geom_text(aes(y=len+sd_value+1,label=Sigi),size=8)
df<-read.csv("example_data/003-2.csv",header=T)
df
ggplot(data=df,aes(x=dose,y=len,group=supp))+
geom_line(aes(color=supp))+geom_point(aes(color=supp))+
geom_errorbar(aes(ymin=len-sd_value,
ymax=len+sd_value,color=supp),
width=0.05)+
theme_bw()+
scale_color_manual(values=c("#33a02c", "#e31a1c"))
“R語(yǔ)言怎么實(shí)現(xiàn)柱形圖”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。