This is part of my df:
CWRES ID AGE BMI WGT
3 0.59034000 1 37.5 20.7 64.6
4 1.81300000 1 37.5 20.7 64.6
5 1.42920000 1 37.5 20.7 64.6
6 0.59194000 1 37.5 20.7 64.6
7 0.30886000 1 37.5 20.7 64.6
8 -0.14601000 1 37.5 20.7 64.6
9 -0.19776000 1 37.5 20.7 64.6
10 0.74208000 1 37.5 20.7 64.6
11 -0.69280000 1 37.5 20.7 64.6
38 -2.42900000 1 37.5 20.7 64.6
39 -0.25732000 1 37.5 20.7 64.6
40 -0.49689000 1 37.5 20.7 64.6
41 -0.11556000 1 37.5 20.7 64.6
42 0.91036000 1 37.5 20.7 64.6
43 -0.24766000 1 37.5 20.7 64.6
44 -0.14962000 1 37.5 20.7 64.6
45 -0.45651000 1 37.5 20.7 64.6
48 0.53237000 2 58.5 23.0 53.4
49 -0.53284000 2 58.5 23.0 53.4
50 -0.33086000 2 58.5 23.0 53.4
51 -0.56355000 2 58.5 23.0 53.4
52 0.00883120 2 58.5 23.0 53.4
53 -1.00650000 2 58.5 23.0 53.4
80 0.85810000 2 58.5 23.0 53.4
81 -0.71715000 2 58.5 23.0 53.4
82 0.44346000 2 58.5 23.0 53.4
83 1.09890000 2 58.5 23.0 53.4
84 0.98726000 2 58.5 23.0 53.4
85 0.19667000 2 58.5 23.0 53.4
86 -1.32570000 2 58.5 23.0 53.4
89 -4.56920000 3 43.5 26.7 66.2
90 0.75174000 3 43.5 26.7 66.2
...
I want to plot this:
for(i in names(tab3)[2:5]) {
df2 <- tab3[, c(i, "CWRES")]
p99 = ggplot(tab3) + geom_point(aes_string(x = i, y = "CWRES"))
print(p99)
}
The problem is that if I want to change the xlab it does not work because I am using aes_string()
.
This does not work:
names(tab3) = c("ID","age [years]","BMI (kg/m2)","body weight ,kg")
for(i in names(tab3)[2:5]) {
df2 <- tab3[, c(i, "CWRES")]
p99 = ggplot(tab3) + geom_point(aes_string(x = i, y = "CWRES"))
print(p99)
}
I also tried another way:
namecol = c("ID","age [kgg]","BMI","bodyweight")
for(i in names(tab3)[2:5]) {
df2 <- tab3[, c(i, "CWRES")]
p99 = ggplot(tab3) + geom_point(aes_string(x = i, y = "CWRES")) +
ylab("CWRES") +
for(a in namecol[1:4]) {
xlab(namecol[a])
}
print(p99)
}
but it does not work either.
How can I get this to work?