在ggvis中,属性可以被赋值为
mtcars %>%
ggvis(~wt,~mpg, shape= ~factor(cyl)) %>%
layer_points()

不过,我不知道如何设定天平。我相信它应该使用scale_nominal。但到目前为止我没能成功。
我可以改变事情的顺序
mtcars %>%
ggvis(~wt,~mpg, shape= ~factor(cyl)) %>%
layer_points() %>% scale_nominal('shape',c(8,6,4))

但我不能强迫他们成为我想要的形状。
在ggplot中,我会使用scale_shape_manual来实现这个目标
mtcars %>% ggplot(aes(x = wt,y = mpg, shape= factor(cyl))) +
geom_point() +
scale_shape_manual(values = c('4' = 15, '6' = 18, '8' = 3))

请注意,如果删除所有4s,其他形状将保留下来。
mtcars %>%
filter(cyl!=4) %>%
ggplot(aes(x = wt,y = mpg, shape= factor(cyl))) +
geom_point() +
scale_shape_manual(values = c('4' = 15, '6' = 18, '8' = 3))

发布于 2017-05-08 22:46:19
与ggplot的scale_{whatever}_manual不同,您不能在单个变量中设置值的范围。在scale_nominal中,domain和range变量控制这些属性。
mtcars %>%
ggvis(~wt,~mpg, shape= ~factor(cyl)) %>%
layer_points() %>%
scale_nominal('shape',domain = c(4,6,8),range = c('square','cross','diamond'))

请注意,ggvis允许有限的形状调色板:圆形(默认)、方形、交叉、菱形、三角形向上或三角形向下。
https://stackoverflow.com/questions/43816274
复制相似问题