layer_bars(stack=FALSE) not dodging (but works in simple example)
joshmorel opened this issue · 1 comments
joshmorel commented
Hello, I would like to create a grouped barchart (which is not stacked) using ggvis. #164 I read some other issues which identified this was a work in progress, but since it works in a simple case I assume it is now a usable feature?
I've included some reproducible code for the case that doesn't work. There is also a simple case which does work - so I'm at a loss at this point to troubleshoot further. In my case, instead of dodging the bars, it just paints them on top of one another (both RStudio and Chrome).
I'm using RStudio version 0.99.491 on max
library(XML)
library(ggvis)
library(dplyr)
library(tidyr)
##Farm census data
farms_by_area <- "http://www.omafra.gov.on.ca/english/stats/census/size2.htm"
tables <- readHTMLTable(farms_by_area)
farms_by_area <- tables[[2]]
farms_by_area <- farms_by_area[,c(1,2,4,6,8)]
colnames(farms_by_area)[1] <- "farm_size"
##Do not include Total, or breakdown beyond 1,600 and over which only applies to last two years
##Those are still counted in 1,600 acrs and over row
farms_by_area = farms_by_area[1:11,]
farms_by_area %>% gather(year,count,-farm_size) %>%
mutate(year=gsub("\\s","",year),count=as.integer(gsub("[-,]","",as.character(count)))) %>%
mutate(farm_size = ordered(farm_size, levels = c("Under 10 acres","10 - 69 acres","70 - 129 acres","130 - 179 acres","180 - 239 acres",
"240 - 399 acres","400 - 559 acres","560 - 759 acres","760 - 1,119 acres","1,120 - 1,599 acres","1,600 acres and over")
),year = factor(year)
) -> farms_by_area_clean
## Does not work - painting bars on top of one another instead of dodging
farms_by_area_clean %>% ggvis(x= ~year, y= ~count, fill = ~farm_size) %>%
layer_bars(stack=FALSE)
## This simple example works fine however
steps <-c("A","B","C","D","A","B","C","D")
ratio <-c(1.1,1.5,1.7,1.4,1.5,1.7,1.4,1.9)
feature <-c("cc","cc","cc","cc","ca","ca","ca","ca")
shrink <- data.frame(steps,ratio,feature)
shrink %>%
mutate(steps_feature = factor(paste(steps, feature))) %>%
ggvis(x= ~steps_feature, y= ~ratio, fill = ~feature) %>%
layer_bars(stack = FALSE)
> devtools::session_info()
Session info ------------------------------------------------------------------------
setting value
version R version 3.2.4 Revised (2016-03-16 r70336)
system x86_64, mingw32
ui RStudio (0.99.491)
language (EN)
collate English_Canada.1252
tz America/New_York
date 2016-05-07
Packages ----------------------------------------------------------------------------
package * version date source
assertthat 0.1 2013-12-06 CRAN (R 3.2.1)
DBI 0.3.1 2014-09-24 CRAN (R 3.2.1)
devtools 1.9.1 2015-09-11 CRAN (R 3.2.2)
digest 0.6.8 2014-12-31 CRAN (R 3.2.1)
dplyr * 0.4.2 2015-06-16 CRAN (R 3.2.1)
ggvis * 0.4.2 2015-06-06 CRAN (R 3.2.5)
htmltools 0.2.6 2014-09-08 CRAN (R 3.2.1)
httpuv 1.3.3 2015-08-04 CRAN (R 3.2.1)
jsonlite 0.9.17 2015-09-06 CRAN (R 3.2.2)
lazyeval 0.1.10 2015-01-02 CRAN (R 3.2.1)
magrittr 1.5 2014-11-22 CRAN (R 3.2.1)
memoise 0.2.1 2014-04-22 CRAN (R 3.2.1)
mime 0.4 2015-09-03 CRAN (R 3.2.2)
plyr 1.8.3 2015-06-12 CRAN (R 3.2.1)
R6 2.1.1 2015-08-19 CRAN (R 3.2.2)
Rcpp 0.12.2 2015-11-15 CRAN (R 3.2.3)
reshape2 1.4.1 2014-12-06 CRAN (R 3.2.1)
rstudioapi 0.3.1 2015-04-07 CRAN (R 3.2.1)
shiny 0.12.2 2015-08-05 CRAN (R 3.2.3)
stringi 1.0-1 2015-10-22 CRAN (R 3.2.2)
stringr 1.0.0 2015-04-30 CRAN (R 3.2.1)
tidyr * 0.2.0 2014-12-05 CRAN (R 3.2.1)
XML * 3.98-1.3 2015-06-30 CRAN (R 3.2.1)
xtable 1.7-4 2014-09-12 CRAN (R 3.2.1)
jsonbecker commented