大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章主要介绍“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语言数据可视化的实现方法是什么”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!