2017-04-20 88 views
2

我有興趣將一行1和0繪製爲單行的綠色和紅色點。我是R新手,還沒有找到一個繪圖解決方案來做到這一點。例如:numbers = c(1,0,0,1,1,1,1,1,1,0,1,0,1,0)。該地塊作爲(green dot, red dot, red dot, green dot, green dot,...)繪製R中的顏色點代表0和1的點

回答

1
plot(x = seq_along(numbers), 
    y = rep(1, length(numbers)), 
    pch = 19, 
    col = c("red","green")[1 + (numbers == 1)], 
    ann = FALSE, 
    axes = FALSE) 

enter image description here

+0

由於單行,這正是我一直在尋找。 –