我正在尝试创建一个坐标向量,以便稍后使用 ggplot 进行绘图。
假设我有一个看起来像这样的数据框:
keys = c("aa", "aa", "ac", "ag", "gg", "at", "ca", "gc", "cc", "cg", "gt", "gg", "tt", "ta", "ga", "tg")
values = c(9.318796e-05, 1.863759e-04, 5.591278e-04, 1.863759e-04, 2.795639e-04, 9.318796e-05, 9.318796e-05, 1.863759e-04, 1.863759e-04, 2.795639e-04, 2.795639e-04, 1.863759e-04, 2.795639e-04, 9.318796e-05, 9.318796e-05, 5.591278e-04)
df = data.frame(keys, values)
现在我想创建一个矩阵,它会给每个字母自己的空间,特别是:
A(-1,1) [左上],
T(1,-1)[右下],
G(1,1)[右上]和
C(-1,-1)[左下]
为此,我做了:
array_size = sqrt(4^k) #Where k = 2
graph_coord = c()
for(i in range(array_size)){
graph_coord = append(graph_coord, array_size[1])
} ##Give the graph_coord its size
maxx = array_size
maxy = array_size
posx = 1
posy = 1
for(i in df$keys){
##This part is for getting each individual letter of each element of keys.
for(j in i[[1]]){
##If the individual letter is a T then the actual position on x should be maxx/2
if (i == "T"){
posx = maxx/2
}else if(i == "C"){
posy = maxy/2
}else if(i == "G"){
posx =maxx/2
posy =maxy/2
}
###Up until this point I think that the code is doing well,
###I can grab individual letters of each element of key and
###see which one they are and then decide to move them according
###to the initial coordinate maxx and maxy. The next part escapes me:
maxx = maxx/2
maxy /=2 ##This /= is customary to python what would be the R equivalent?
##Append the graph coordinates with the df$values.
graph_coord = append(graph_coord, posy-1, posx-1, prob) ##This part is especially hard for me to grasp and as such I have left the idea, but the code snippet is absolutely incorrect.
}
此代码仍在进行中。我正在尝试重新创建这里所做的事情:从混沌游戏表示中提取的频率表