新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
R語言怎么實現(xiàn)柱形圖
本篇內(nèi)容介紹了“R語言怎么實現(xiàn)柱形圖”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
我們提供的服務(wù)有:網(wǎng)站制作、成都網(wǎng)站建設(shè)、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、硚口ssl等。為成百上千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的硚口網(wǎng)站制作公司
柱形圖
普通柱形圖 簇狀柱形圖 堆積柱形圖
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語言怎么實現(xiàn)柱形圖”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!
當(dāng)前文章:R語言怎么實現(xiàn)柱形圖
分享鏈接:http://fisionsoft.com.cn/article/jedogs.html