Open patilv opened 8 years ago
Resurrecting memories from the past :) Try this:
library(rcdimple)
df <- data.frame(
U5 = c("NULL","X")[rep(c(rep(1,1),rep(2,1)),2)]
, Status = c(rep("A",2),rep("B",2))
, Count = c(10000,5000,20000,15000)
)
a21 <- dimple(
x = "Status",
y = "Count",
groups = "U5",
data = df,
type = "bar"
)
(a21 <- xAxis(a21, type = "addCategoryAxis", orderRule = "Status"))
(a21a <- yAxis(a21, type = "addMeasureAxis", orderRule = "U5"))
(a21b <- yAxis(a21, type = "addMeasureAxis", orderRule = "Count"))
I think plotly also has this functionality.
Let's try this example..
library(likert) library(rcdimple) library(tidyr) data(pisaitems) items28 <- pisaitems[, substr(names(pisaitems), 1, 5) == "ST24Q"] l28 <- likert(items28) l28=data.frame(l28$results) gathered=l28 %>% gather(Response,Percent,2:5)
dimple( Item ~ Percent, groups = "Response", data = gathered, type = "bar" ) %>% xAxis(type="addMeasureAxis") %>% yAxis(type="addCategoryAxis") %>% add_legend()
In this example, how do we switch the stacking group order? i.e., if we wanted to pass a specific sequence for variable that goes with the groups param, how can that be done?
ex_data <- read.delim( "http://pmsi-alignalytics.github.io/dimple/data/example_data.tsv" ) colnames(ex_data) <- gsub("[.]","", colnames(ex_data))
ex_data$Channel=ordered(ex_data$Channel, levels = c("Supermarkets","Hypermarkets"))
ex_data %>% dimple(x ="Month", y = "UnitSales", groups = "Channel", type = "bar", width = 590, height = 400 ) %>% set_bounds( x = 60, y = 30, width = 510, height = 290 ) %>% xAxis(orderRule = "Date") %>% add_legend( ) %>% add_title( text = "Unit Sales each Month by Channel" )