您好,登錄后才能下訂單哦!
這篇文章主要介紹“R語言數據可視化的實現方法是什么”,在日常操作中,相信很多人在R語言數據可視化的實現方法是什么問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”R語言數據可視化的實現方法是什么”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
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))
到此,關于“R語言數據可視化的實現方法是什么”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。