Graphics Reference
In-Depth Information
tg
supp dose length
OJ 0.5 13.23
OJ 1.0 22.70
OJ 2.0 26.06
VC 0.5 7.98
VC 1.0 16.77
VC 2.0 26.14
str(tg)
'data.frame' : 6 obs. of 3 variables:
$ supp : Factor w / 2 levels "OJ" , "VC" : 1 1 1 2 2 2
$ dose : num 0.5 1 2 0.5 1 2
$ length: num 13.23 22.7 26.06 7.98 16.77 ...
NOTE
If the xvariable is a factor, you must also tell ggplot() to group by that same variable, as described
momentarily.
Line graphs can be used with a continuous or categorical variable on the x-axis. Sometimes the
variable mapped to the x-axis is conceivedof as being categorical, even when it's stored as a
number. In the example here, there are three values of dose : 0.5, 1.0, and 2.0. You may want to
treat these as categories rather than values on a continuous scale. To do this, convert dose to a
factor ( Figure 4-7 ):
ggplot(tg, aes(x = factor(dose), y = length, colour = supp, group = supp)) + geom_line()
Search WWH ::




Custom Search