ggvis:具有整数刻度的x轴

MYa*_*208 4 r graph scale ggvis

我想得到x轴的整数用于ggvis绘图.

MWE

df <- 
  structure(list(Factor = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 
  2L, 3L, 1L, 2L, 3L), .Label = c("A", "B", "C"), class = "factor"), 
  X = c(15.5133333333333, 14.63, 14.41, 14.1266666666667, 13.1833333333333, 
  12.9466666666667, 13.6133333333333, 13.55, 13.5333333333333, 
  11.5566666666667, 11.3066666666667, 11.4566666666667), Y = c(20L, 
  20L, 20L, 40L, 40L, 40L, 70L, 70L, 70L, 100L, 100L, 100L)), .Names = c("Factor", 
  "X", "Y"), row.names = c(NA, -12L), class = "data.frame")

library(ggvis)

ggvis(data=df
      , x= ~X
      , y= ~Y
      , fill= ~Factor
      , stroke = ~Factor) %>% 
  arrange(Y) %>%
  group_by(Factor) %>%
  layer_points(shape=~Factor) %>% 
  layer_paths(fill := NA)  %>%
  add_axis('x', orient=c('bottom'), format='####') 
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

一种可能性是使用values=seq(from=10, to=16, by=1)add_axis().但这种方法并不是自动化的.

nru*_*ell 5

format参数设置为'd'仅在轴标签中显示整数值:

library(ggvis)
library(dplyr)
##
ggvis(data=df
      , x= ~X
      , y= ~Y
      , fill= ~Factor
      , stroke = ~Factor) %>% 
  arrange(Y) %>%
  group_by(Factor) %>%
  layer_points(shape=~Factor) %>% 
  layer_paths(fill := NA)  %>%
  add_axis('x', orient=c('bottom'), format='d')
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

更多的信息d3格式规范可在此页面,如提到的通用属性的节ggvis指南.