用ggvis重新创建ggplot geom_point图?

时间:2015-04-30 13:49:29

标签: r ggplot2 ggvis

假设我有这些数据:

DF <- data.frame(x=as.factor(c("A","A", "B", "B")),
                 y=c(0.02, 0.016, 0.012, 0.008),
                 type = as.factor(c('d','f','d','f')),
                 se=c(0.023, 0.014, 0.011, 0.016))

使用ggplot我创建了这个图:

DF %>% ggplot(aes(x = x, y=y)) +
  geom_point(aes(size=se, fill= x), 
             pch=21,  
             alpha=2/3)  + 
  scale_size("SE", range=c(10,40)) + 
  geom_point(aes(shape= type), size=3) + 
  scale_fill_discrete(guide=FALSE) +
  scale_shape(name='Type')

我想创建相同的图形,或者与ggvis非常相似的图形。有没有相当于scale_size的东西?

现在我能做的最好的就是:

DF %>% 
  ggvis(x = ~x, y = ~y, 
        stroke = ~type, strokeWidth := 2, 
        fill=~x, size=~se) %>% 
  layer_points() %>%
  add_legend(c("stroke"), 
             title = "Type", 
             properties = legend_props(legend = list(y = 0))) %>%
  add_legend('size', title = "SE", 
             properties = legend_props(legend = list(y = 50))) %>%
  hide_legend(scales = 'fill')

谢谢!

0 个答案:

没有答案