您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章主要介绍“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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。