Search code examples
rbar-chartggvis

Bar Plot x-axis order in R ggvis


I am experimenting to use ggvis for my daily report. One issue I came across is that for a dataset that I intended to plot x-axis as in the data order. However, the actual plot shows up in the alphabet order.

Is there any hidden parameters to change x-axis order for Bar chart in R?

Step    LER
Pre 3.2
DS  2.8
SiARC   2.2
OPL 1.9
ILD 1.6
Oxide   1.5

library(ggvis)
ler <- read.csv("shinyapps/EUV/data/by_step_LER.csv")
ler %>% ggvis(x = ~Step, y = ~LER) %>% layer_bars()

Solution

  • library(ggvis)
    
    ler <- structure(list(Step = structure(1:6, .Label = c("Pre", "DS", "SiARC", "OPL", "ILD", "Oxide"), class = "factor"), LER = c(3.2, 2.8, 2.2, 1.9, 1.6, 1.5)), .Names = c("Step", "LER"), row.names = c(NA, -6L), class = "data.frame")
    
    ler$Step <- factor(ler$Step, levels = ler$Step)
    
    ler %>% ggvis(x = ~Step, y = ~LER) %>% layer_bars()
    

    enter image description here