csu_bar_top: csu_bar_top

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/csu_bar_top.R

Description

csu_bar_top plots top X single-sided or double-sided bar chart.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
csu_bar_top(df_data,
	var_value, 
	var_bar,
	group_by=NULL,
	nb_top = 10,
	plot_title=NULL,
	plot_subtitle=NULL,
	xtitle= NULL,
	label_by=NULL,
	color=NULL,
	digits = 1)

Arguments

df_data

Data (need to be R data.frame format, see examples to import csv file).

var_value

Value variable.
There must be only 1 value for each bar.

var_bar

Bar label variable.

group_by
  • Single-sided bar chart. NULL (default)

  • Double-sided bar chart. Variable name with exactly 2 values. (For example, "sex").

Must be filled if label_by argument is defined.

nb_top

Lowest Rank included. Default is 10.

plot_title

Title of the plot. (For example, "Top 10 cancer sites").

plot_subtitle

Subtitle of the plot. (For example, "Males").

xtitle

x-axe title. (For example, "Number of cases").

label_by

2 values vector. Will overwrite the legend label for double-sided bar chart. (See group_by).
For example: c("Male", "Female").

color

The color codes are hexadecimal (e.g. "#FF0000") or predefined R color names (e.g. "red").

  • Single-sided bar chart. 1 hexadecimal color code (same color for each bar) or variable name with a color associated to each bar label variable.

  • Double-sided bar chart. 2 values vector. For example: c("#2c7bb6","#b62ca1").

digits

Number of decimal digits. Default: 1

Details

This function plots a top X (default is top 10) bar chart, single-sided or double sided.

Value

Return plots and a data.frame.

Author(s)

Mathieu Laversanne

See Also

csu_group_cases csu_merge_cases_pop csu_asr csu_cumrisk csu_eapc csu_ageSpecific csu_ageSpecific_top csu_time_trend csu_trendCohortPeriod

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
data(data_individual_file)
data(data_population_file)
data(ICD_group_GLOBOCAN)

#Group individual data by:
#5 year age group
#ICD grouping from dataframe ICD_group_GLOBOCAN
#year extract from date of incidence

df_data_year <- csu_group_cases(data_individual_file,
  var_age="age",
  group_by=c("sex", "regcode", "reglabel"),
  df_ICD = ICD_group_GLOBOCAN,
  var_ICD  ="site",
  var_year = "doi")     

#Merge 5-years age grouped data with population by year (automatic) and sex

df_data <- csu_merge_cases_pop(
  df_data_year, 
  data_population_file, 
  var_age = "age_group",
  var_cases = "cases",
  var_py = "pop",
  group_by = c("sex"))


#prepare for calculate ASR
df_data$age_group_label <- NULL # to avoid warning
df_data <- subset(df_data , year == 2012) # to keep only 2012 data
df_data$year <- NULL # to avoid warning

# calculate asr
df_asr <- csu_asr(df_data,
  "age_group", 
  "cases",
  "pop",
  group_by=c("sex", "ICD_group", "LABEL", "reglabel", "regcode"),
  missing_age =19)

#remove Other cancer
df_asr <- subset(df_asr , LABEL != "Other") 
df_asr <- subset(df_asr , LABEL != "Other skin")


#keep male
df_asr_M <- subset(df_asr , sex==1)

#Single sided bar plot 
data1 <- csu_bar_top(
   df_asr_M,
   var_value="cases",
   var_bar="LABEL",
   nb_top = 10,
   plot_title = "Top 10 cancer sites",
   xtitle= "Number of cases",
   color= c("#2c7bb6"),
   digits=0) 

#Double sided bar plot example 1
data2 <- csu_bar_top(
   df_asr,
   var_value="cases",
   var_bar="LABEL",
   group_by="sex",
   nb_top = 15,
   plot_title = "Top 15 cancer sites",
   xtitle= "Number of cases",
   label_by=c("Male", "Female"),
   color = c("#2c7bb6","#b62ca1"),
   digits=0) 

#Double sided bar plot example 2
data3 <- csu_bar_top(
   df_asr,
   var_value="asr",
   var_bar="LABEL",
   group_by="sex",
   nb_top = 10,
   plot_title = "Top 10 cancer sites",
   xtitle= "Age-standardized rate per 100,000",
   label_by=c("Male", "Female"),
   color = c("#2c7bb6","#b62ca1"),
   digits=1) 

Rcan documentation built on July 1, 2020, 10:20 p.m.