ggvis 中的形状名称
Shape names in ggvis
在 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))
请注意,如果我删除所有 4,其他形状将保留
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))
与 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 允许使用有限的形状调色板:圆形(默认)、正方形、十字形、菱形、向上三角形或向下三角形
在 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))
请注意,如果我删除所有 4,其他形状将保留
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))
与 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 允许使用有限的形状调色板:圆形(默认)、正方形、十字形、菱形、向上三角形或向下三角形