-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriting_functions.R
87 lines (64 loc) · 2.01 KB
/
writing_functions.R
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
85
86
87
airtemps <- c(212, 30.3, 78, 32) # airtemps in F
celsius1 <- (airtemps[1]-32)*5/9
celsius2 <- (airtemps[2]-32)*5/9
celsius3 <- (airtemps[3]-32)*5/9
# wrapping the operation into a function
# going to use the `function` function
# function parameters are the inputs the function needs to operate
fahr_to_celsius <- function(fahr){
celsius <- (fahr - 32)*5/9
return(celsius)
}
celcius11 <- fahr_to_celsius(airtemps[1])
celcius4 <- fahr_to_celsius(airtemps[1])
# check it returns as true
celcius11 == celcius4
# celsius*9/5 + 32
# adding Roxygen skeleton-
#' Convert Celsius temperatures to Fahrenheit
#'
#' Could add a longer description if I wished
#'
#' @param celsius The temperature in Celsius
#'
#' @return The temperature in Fahrenheit
#' @export
#'
#' @examples
#'
#' Would need to include an example vector
#'
#'
celsius_to_fahr <- function(celsius){
fahr <- (celsius*9/5) + 32
return(fahr)
}
airtemps_c <- fahr_to_celsius(airtemps)
airtemps_f <- celsius_to_fahr(airtemps_c)
airtemps == airtemps_f
# new function
convert_temps <- function(fahr){
celsius <- (fahr - 32)*5/9
kelvin <- celsius + 273.15
temps <- data.frame(fahr = fahr,
celsius = celsius,
kelvin = kelvin)
return(temps)
}
airtemps <- c(212, 100, 78)
temps_all <- convert_temps(airtemps)
custom_theme <- function(base_size = 9) {
ggplot2::theme(
axis.ticks = ggplot2::element_blank(),
text = ggplot2::element_text(family = 'Helvetica', color = 'gray30', size = base_size),
plot.title = ggplot2::element_text(size = ggplot2::rel(1.25), hjust = 0.5, face = 'bold'),
panel.background = ggplot2::element_blank(),
legend.position = 'right',
panel.border = ggplot2::element_blank(),
panel.grid.minor = ggplot2::element_blank(),
panel.grid.major = ggplot2::element_line(colour = 'grey90', size = .25),
legend.key = ggplot2::element_rect(colour = NA, fill = NA),
axis.line = ggplot2::element_blank()
)
}
library(ggplot2)