您好,登錄后才能下訂單哦!
這篇文章主要介紹“R語言數(shù)據(jù)可視化的實(shí)現(xiàn)方法是什么”,在日常操作中,相信很多人在R語言數(shù)據(jù)可視化的實(shí)現(xiàn)方法是什么問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對(duì)大家解答”R語言數(shù)據(jù)可視化的實(shí)現(xiàn)方法是什么”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
df2<-read.csv("20210410/001.csv",header=T)
p1<-ggplot(data=df2,aes(x=value,y=variable))+
geom_boxplot()+
theme_bw()+
scale_y_discrete(position = "right")+
theme(panel.border = element_blank(),
panel.grid = element_blank(),
axis.line.x = element_line(),
axis.line.y = element_line(),
axis.text.y = element_blank(),
axis.title.y = element_blank())+
labs(x="Predicted \n copy number")+
geom_hline(yintercept = 6.5,lty="dashed")+
annotate(geom="text",
x=-1.2,y=3,label="C degradation",angle=90)+
annotate(geom="text",
x=-1.2,y=12,label="N cycling",angle=90)
p1
df<-read.csv("20210410/002.csv",header=T)
head(df)
df1<-reshape2::melt(df,id.vars="Sample")
head(df1)
head(df1)
df1%>%
#reshape2::melt(id.vars="Sample")%>%
mutate(group_1 = case_when(
value <= 0 ~ "A",
TRUE ~ "B"
))%>%
mutate(group_2=case_when(
value >= -1 & value < -0.7 ~ "[-1,-0.7)",
value >= -0.7 & value < -0.5 ~ "[-0.7,-0.5)",
value >= -0.5 & value < -0.3 ~ "[-0.5,-0.3)",
value >= -0.3 & value <= 0 ~ "[-0.3,0]",
value > 0 & value <= 0.3 ~ "(0,0.3)",
value > 0.3 & value <= 0.5 ~ "(0.3,0.5]",
value > 0.5 & value <= 0.7 ~ "(0.5,0.7]",
value > 0.7 & value <= 1 ~ "(0.7,1]",
))%>%
mutate(value_1=case_when(
value >= -1 & value < -0.7 ~ -0.8,
value >= -0.7 & value < -0.5 ~ -0.6,
value >= -0.5 & value < -0.3 ~ -0.4,
value >= -0.3 & value <= 0 ~ -0.2,
value > 0 & value <= 0.3 ~ 0.2,
value > 0.3 & value <= 0.5 ~ 0.4,
value > 0.5 & value <= 0.7 ~ 0.6,
value > 0.7 & value <= 1 ~ 0.8,
)) -> df3
df4<-data.frame(
x = seq(0.5,6.5,1),
xend = seq(0.5,6.5,1),
y = -Inf,
yend = Inf
)
df4
df5<-data.frame(
x = -Inf,
xend = Inf,
y = seq(0.5,15.5,1),
yend = seq(0.5,15.5,1)
)
p2<-ggplot(data=df3,aes(x=Sample,y=variable))+
geom_point(aes(size=abs(value_1),
color=factor(value_1)),
shape=15)+
scale_color_manual(values = c(rep("#fe0000",4),
rep("#009ccc",4)))+
theme_bw()+
theme(panel.grid = element_blank(),
panel.border = element_blank(),
axis.ticks = element_blank(),
legend.position = "none")+
geom_segment(data=df4,aes(x=x,xend=xend,y=y,yend=yend),
color="grey")+
geom_segment(data=df5,aes(x=x,xend=xend,y=y,yend=yend),
color="grey")+
scale_size_continuous(range = c(2,10))+
scale_y_discrete(position = "right",
expand = c(0,0))+
labs(x=NULL,y=NULL)+
scale_x_discrete(expand = c(0,0))
p2+
geom_segment(x=7.3,xend=7.3,
y=10,yend = 15)+
geom_segment(x=7,xend=7,
y=7,yend = 9)+
geom_segment(x=7,xend=7,
y=1,yend = 6)+
annotate("text",x=6,y=13,label="group_A",
angle=90,vjust=11)+
annotate("text",x=6,y=8,label="group_B",
angle=90,vjust=10)+
annotate("text",x=6,y=4,label="group_C",
angle=90,vjust=10)+
theme(plot.margin = unit(c(0.2,2,0.2,0.3),'cm'))+
coord_cartesian(clip = "off") -> p2_1
p2_1
p3<-ggplot(data = df6,aes(x=x,y=y))+
geom_point(aes(size=value,color=group),shape=15)+
geom_text(aes(x=x+0.1,label=label))+
scale_size_continuous(range = c(2,10))+
scale_color_manual(values = c("#fe0000","#009ccc"))+
theme(panel.background = element_blank(),
legend.position = "none",
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
plot.margin = unit(c(0.2,1,0.2,0.2),"cm"))+
ylim(0,15)+
coord_cartesian(clip = "off")+
theme(aspect.ratio = 11)
p3
p1+p2_1+p3+
plot_layout(widths = c(1,2,0.4))
到此,關(guān)于“R語言數(shù)據(jù)可視化的實(shí)現(xiàn)方法是什么”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。