ordered_factor: Creates an ordered factor based on order of another variable

Description Usage Arguments Details Value Examples

Description

Creates an ordered factor based on order of another variable

Usage

1

Arguments

var

variable to be converted into a factor

seq

variable that implies the sequence of var when the function order is applied to it

Details

This function helps to re-order groups in a ggplot2 plot. See example below.

Value

factor(var) with the implied order by seq.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
 ## Not run: 

 require(ggplot2)
 require(dplyr)

 economics_long <- economics_long %>% group_by(variable) %>% 
	 mutate( value01_mean=mean(value01) ) 

	economics_long <- ungroup(economics_long) %>% 
	 mutate(variable_mean_ordered = ordered_factor(as.character(variable),value01_mean) )

 ggplot(economics_long, aes(date, value01, colour = variable)) +
 	geom_line()

 ggplot(economics_long, aes(date, value01, colour = variable_mean_ordered)) +
 	geom_line()

 
## End(Not run)

sumtxt/datatools documentation built on May 30, 2019, 8:38 p.m.