点图与多个类别 - R [英] Dot Plots with multiple categories - R
问题描述
我绝对是R的新手,可以对数据进行可视化处理,所以请耐心等待。
我希望创建七个分类样本的并排点图,其中有许多与各个基因名称相对应的基因表达值。 mydata.csv文件如下所示:
B27 B28 B30 B31 LTNP5.IFN.1 LTNP5.IFN.2 LTNP5.IL2。 1
1 13800.91 13800.91 13800.91 13800.91 13800.91 13800.91 13800.91
2 6552.52 5488.25 3611.63 6552.52 6552.52 6552.52 6552.52
3 3381.70 1533.46 1917.30 2005.85 3611.63 4267.62 5488.25
4 2985.37 1188.62 1051.96 1362.32 2717.68 2985.37 5016.01
5 1917.30 2862.19 2625.29 2493.26 2428.45 2717.68 4583.02
6 990.69 777.97 1269.05 1017.26 5488.25 5488.25 4267.62
我希望每个样本数据在一个图中以自己的点图组织。此外,如果我可以指出个人数据点的兴趣,那就太好了。
谢谢!
考虑到[玩具]在一个名为 a
的数据框中:
library(reshape2)
library(ggplot2)
a $ trial< -1:dim(a)[1]#另外,nrow(a)
b <-melt(data = a,varnames = colnames(a)[ 1:7],id.vars =trial)
b $ variable< -as.factor(b $ variable)
ggplot(b,aes(trial,value))+ geom_point()+ facet_wrap (〜变量)
产生
< a href =https://i.stack.imgur.com/dw9nd.png =nofollow noreferrer>
我们做了什么:
加载了所需的库( reshape2
将宽转换为长,并将 ggplot2
转换为,以及plot); melt
将数据转换成长格式(更难读,更容易处理),然后用 ggplot
进行绘图。
我介绍了 trial
指向每个运行每个变量进行了测量,所以我绘制了<$ c $在变量
的每个级别上,c> trial vs value
。 facet_wrap
部分将每个图放入由变量
确定的子图区域中。
I'm definitely a neophyte to R for visualizing data, so bear with me.
I'm looking to create side-by-side dot plots of seven categorical samples with many gene expression values corresponding with individual gene names. mydata.csv file looks like the following
B27 B28 B30 B31 LTNP5.IFN.1 LTNP5.IFN.2 LTNP5.IL2.1
1 13800.91 13800.91 13800.91 13800.91 13800.91 13800.91 13800.91
2 6552.52 5488.25 3611.63 6552.52 6552.52 6552.52 6552.52
3 3381.70 1533.46 1917.30 2005.85 3611.63 4267.62 5488.25
4 2985.37 1188.62 1051.96 1362.32 2717.68 2985.37 5016.01
5 1917.30 2862.19 2625.29 2493.26 2428.45 2717.68 4583.02
6 990.69 777.97 1269.05 1017.26 5488.25 5488.25 4267.62
I would like each sample data to be organized in its own dot plot in one graph. Additionally, if I could point out individual data points of interest, that would be great.
Thanks!
Considering your [toy] data is stored in a data frame called a
:
library(reshape2)
library(ggplot2)
a$trial<-1:dim(a)[1] # also, nrow(a)
b<-melt(data = a,varnames = colnames(a)[1:7],id.vars = "trial")
b$variable<-as.factor(b$variable)
ggplot(b,aes(trial,value))+geom_point()+facet_wrap(~variable)
produces
What we did:
Loaded required libraries (reshape2
to convert from wide to long and ggplot2
to, well, plot); melt
ed the data into long formmat (more difficult to read, easier to process) and then plotted with ggplot
.
I introduced trial
to point to each "run" each variable was measured, and so I plotted trial
vs value
at each level of variable
. The facet_wrap
part puts each plot into a subplot region determined by variable
.
这篇关于点图与多个类别 - R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!