Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ggplot(survey,aes(x=age))+stat_bin(aes(n=nrow(h3),y=..count../n), binwidth=10)
- +scale_y_continuous(formatter = "percent", breaks=c(0, 0.1, 0.2))
- + facet_grid(hospital ~ .)
- + opts(panel.background = theme_blank())
- # Using the Iris data
- > i <- iris
- > levels(i$Species)
- [1] "setosa" "versicolor" "virginica"
- > levels(i$Species) <- c("S", "Ve", "Vi")
- > ggplot(i, aes(Petal.Length)) + stat_bin() + facet_grid(Species ~ .)
- hospital_names <- list(
- 'Hospital#1'="Some Hospital",
- 'Hospital#2'="Another Hospital",
- 'Hospital#3'="Hospital Number 3",
- 'Hospital#4'="The Other Hospital"
- )
- hospital_labeller <- function(variable,value){
- return(hospital_names[value])
- }
- ggplot(survey,aes(x=age)) + stat_bin(aes(n=nrow(h3),y=..count../n), binwidth=10)
- + facet_grid(hospital ~ ., labeller=hospital_labeller)
- ...
- plot_labeller <- function(variable,value){
- if (variable=='facet1') {
- return(facet1_names[value])
- } else {
- return(facet2_names[value])
- }
- }
- plot_labeller <- function(variable,value){
- if (variable=='facet1') {
- return(facet1_names[value])
- } else if (variable=='facet2') {
- return(facet2_names[value])
- } else {
- return(as.character(value))
- }
- }
- hospital_names <- c(
- `Hospital#1` = "Some Hospital",
- `Hospital#2` = "Another Hospital",
- `Hospital#3` = "Hospital Number 3",
- `Hospital#4` = "The Other Hospital"
- )
- ... + facet_grid(hospital ~ ., labeller = as_labeller(hospital_names))
- library(ggplot2)
- labeli <- function(variable, value){
- names_li <- list("versicolor"="versi", "virginica"="virg")
- return(names_li[value])
- }
- dat <- subset(iris,Species!="setosa")
- ggplot(dat, aes(Petal.Length)) + stat_bin() + facet_grid(Species ~ ., labeller=labeli)
- labeli2 <- function(variable, value){
- value <- droplevels(value)
- names_li <- list("versicolor"="versi", "virginica"="virg")
- return(names_li[value])
- }
- dat <- subset(iris,Species!="setosa")
- ggplot(dat, aes(Petal.Length)) + stat_bin() + facet_grid(Species ~ ., labeller=labeli2)
- facet_grid( hospital ~ room, labeller = labeller(hospital = as_labeller(hospital_names)))
- facet_grid( hospital ~ room, labeller = labeller(hospital = as_labeller(hospital_names),
- room = as_labeller(room_names)))
- facet_grid(
- yfacet~xfacet,
- labeller = labeller(
- yfacet = c(`0` = "an y label", `1` = "another y label"),
- xfacet = c(`10` = "an x label", `20` = "another x label)
- )
- )
- ggplot(transform(survey, survey = factor(survey,
- labels = c("Hosp 1", "Hosp 2", "Hosp 3", "Hosp 4"))), aes(x = age)) +
- stat_bin(aes(n = nrow(h3),y=..count../n), binwidth = 10) +
- scale_y_continuous(formatter = "percent", breaks = c(0, 0.1, 0.2)) +
- facet_grid(hospital ~ .) +
- opts(panel.background = theme_blank())
- plot_labeller <- function(variable,value, facetVar1='<name-of-1st-facetting-var>', var1NamesMapping=<pass-list-of-name-mappings-here>, facetVar2='', var2NamesMapping=list() )
- {
- #print (variable)
- #print (value)
- if (variable==facetVar1)
- {
- value <- as.character(value)
- return(var1NamesMapping[value])
- }
- else if (variable==facetVar2)
- {
- value <- as.character(value)
- return(var2NamesMapping[value])
- }
- else
- {
- return(as.character(value))
- }
- }
- clusteringDistance_names <- list(
- '100'="100",
- '200'="200",
- '300'="300",
- '400'="400",
- '600'="500"
- )
- plot_labeller <- function(variable,value, facetVar1='clusteringDistance', var1NamesMapping=clusteringDistance_names, facetVar2='', var1NamesMapping=list() )
- ggplot() +
- facet_grid(clusteringDistance ~ . , labeller=plot_labeller)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement