我正在探索racket
中的绘图工具,我不得不说,迄今为止我对它印象非常深刻。但是,我遇到了一个小小的困难。单色球拍中的散点图
我试图做一个散点图,其中每个点都有自己的颜色(用于可视化分类算法)。但是,我不知道如何让每个点都有自己的颜色。可能吗?
这里是我到目前为止已经试过:
(define (random-choice l)
(list-ref l (random (length l))))
(define (scatter data)
(let ([x-max (apply max (map first data))]
[x-min (apply min (map first data))]
[y-max (apply max (map second data))]
[y-min (apply min (map second data))]
[colors (build-list 20
; here I am trying to create a list of desired colors
; ,but an error tells me that only single elements are accepted
(λ _ (random-choice (list "red" "blue")))])
(parameterize ([plot-new-window? #t]
[point-sym 'dot]
[point-size 20])
(plot (points data
#:color colors)
#:x-max x-max
#:x-min x-min
#:y-max y-max
#:y-min y-min))))
大致相当于在R
是:
c <- data.frame(x=rnorm(10),y=rnorm(10))
colors <- sample(c("red","blue"),10,replace=TRUE)
plot(c$y,c$x,col=colors)
顺便说一句,我会欢迎任何(所有)评论我的代码,例如简化绘图的边界规范。