Ggvis chart with error bars - custom axis text

I am trying to generate a ggvis graph with errors. I decided to display the averages as points and error bars as rectangles. Here is my dataset:

mivector<-c(1.5,2,2.5,2,2.5,3,2.5,3,3.5)
treats<-c("A","A","A","B","B","B","C","C","C")

library(ggvis)
library(dplyr)

plotdf<-data.frame(mivector,treats)

plotdf<- plotdf %>% group_by(treats) %>% 
summarise(mimean=mean(mivector),misd=sd(mivector)) %>%
mutate(milow=mimean-misd,mihigh=mimean+misd,mileft=as.numeric(treats)-0.005,miright=as.numeric(treats)+0.005,treatsno=as.numeric(treats)) %>% 
select(-misd)

      

And here is the build code I am trying to do:

plotdf %>% ggvis() %>% layer_points(~treatsno,~mimean) %>%
layer_rects(prop("x",~mileft),prop("y",~milow),prop("x2",~miright),prop("y2",~mihigh),fillOpacity:=1) %>%
scale_numeric("y", domain = c(0, 5)) %>%
add_axis("y",grid=F) %>%
add_axis("x",ticks=length(plotdf$treats),grid=F,properties=axis_props(labels=list(text=c("a","b","c"))))

      

I am stuck at the point that I am not able to assign the labels correctly. Instead of 3 ticks with the text "a", "b" and "c" respectively, I have "a, b, c" for each tick.

Could you please point out what I am doing wrong? Maybe there is a much easier way to make error lines that I am not aware of?

Thank you in advance!

+3


source to share





All Articles