具有不同颜色和pch的情节

时间:2019-11-14 22:46:30

标签: r scatter-plot

我有这张桌子:

structure(list(Samples = structure(1:7, .Label = c("Sample1", 
"Sample2", "sample3", "sample4", "sample5", "sample6", "sample7"
), class = "factor"), number_cycle = c(22L, 22L, 26L, 26L, 26L, 
22L, 22L), Quality = structure(c(2L, 2L, 3L, 1L, 1L, 1L, 3L), .Label = c("Bad", 
"Good", "Middle"), class = "factor"), Concentration = c(14L, 
24L, 22L, 40L, 10L, 27L, 12L), Raw_reads = c(100000L, 5000L, 
70000L, 340000L, 4789L, 50000L, 25000L)), class = "data.frame", row.names = c(NA, 
-7L))

我想绘制一个散点图(raw_reads〜浓度),可以观察两个因素的离散度:质量(颜色)和循环次数(pch)。当我尝试这段代码时,我的情节没有任何意义。

palette(rainbow(3))
plot(test$Raw_reads ~ test$Concentration, 
     col = test$Quality, 
     pch = test$number_cycle)
legend(x = "topleft", 
       legend = levels(test$Quality),
       col = rainbow(3), 
       pch = test$number_cycle)

那我该怎么做以获得散点图?

谢谢您的帮助。

1 个答案:

答案 0 :(得分:1)

当您使用基本R绘图时,对于颜色和pch, 您需要指定一个与数据点一样长的向量。我认为对于pch,您需要指定有效数字1:20,对于颜色,请指定因子或字符。解决这个问题的一种方法是调出预定义的pch或col向量:

from threading import Timer
import time
import maya.cmds as cmds

global t
global N
global B

def initGif():
    global t
    global N
    global B

    terminateGif()  
    N = 0

    t = Timer(1.0, startGif)
    t.start()

def startGif():
    global N
    global t
    while N < 1000:
        if N < 1000:
            print "Hello", t # This is where the actual images would iterate instead of "Hello"
            time.sleep(5)
        else:
            terminateGif()
            continue

def terminateGif():
    global t
    global N
    N = 9999999

    try:
        t.cancel()
    except:
        t = "None"
        return

def UI():
    if cmds.window("win", exists = True):
        cmds.deleteUI("win")
    cmds.window("win", w = 500, h = 500)

    cmds.columnLayout()
    cmds.button("stop", c = lambda *args : terminateGif())
    cmds.button("start", c = lambda *args : initGif())

    cmds.showWindow("win")

UI()
initGif()

您还需要两个图例,一个用于颜色,一个用于pch。

enter image description here