2017-08-28 72 views
0

如何使用ifelse和lattice的stripchart()更改某些点的颜色?我可以创建使用stripchart(d, method="stack", offset=1, pch=19, at=1.0)以下点阵图:着色条形码在R

enter image description here

我还可以更改使用参数col情节的颜色,但我试图做更复杂的东西,像这样:ifelse(d>40, "Red", "Black")。 (在这个例子中,小于或等于40的所有点都是黑色的,而高于40的点都是红色的。)我如何将ifelse应用于这个图?

+0

我不知道这是因为这容易带状图()... –

+0

不是。如果我使用dotplot(),我可以使颜色起作用,但是我无法得到点堆叠起来.... – quil

回答

0

也许最简单的办法就是先写一个简单的脚本使用标准的剧情做数学题并画出了带状图()函数

#generate some random numeric data  
set.seed(100) 
    d <- sample(10:80, size = 150, replace = TRUE) 

# count re-occurences of the same value (for plotting on the y-axis) 
td <- do.call(rbind, lapply(1:length(d), (function(i){ 
     c(d[i], 1+ sum(d[1:i] == d[i]))}))) 

# plot 
plot(x= td[,1], y = td[,2], 
     pch=19, ylim = c(0, 20), 
     col = ifelse(td[,1]>49, "red", "blue")) 

enter image description here